Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "system" call fails in perl CGI script - error code 65280

    It is the first time I am trying to use a Perl "system" call in a CGI script. The script is running on Windows XP. Here's the fragment of the code:

    sub errout {
    my $msg = $_[0];
    print "Content-type: text/html\n\n";
    print "<HTML><BODY>\n";
    print "Error: " . $msg . "\n";
    print "</BODY></HTML>";
    }

    ...

    my $indir = '\Contracts\FieldData';
    unless(chdir $indir) {
    errout("Cannot cd to $indir: $!");
    exit;
    }

    my @comargs = ('COPY', '3617_CROSS_BEND_RD_PLANO.txt', '\Contracts\ContractFiles\test.txt');
    system(@comargs) == 0 or errout("system @comargs failed: $?:$!");

    When I run that script in a browser I receive the following error:

    Error: system COPY 3617_CROSS_BEND_RD_PLANO.txt \Contracts\ContractFiles\test.txt failed: 65280:No such file or directory

    Of course, all folders and the file to copy do exist, and the "copy" command works fine in the command prompt window. I looked for answers on the Net, but unfortunately didn't find any explanations. BTW, I have been using "system" calls in a number of my non-CGI Perl scripts, and never had a problem with them.

    Thanks in advance.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Use absolute paths instead of relative.
    Verify that the web server account has proper rights to the directories and file.
    Don't cd to the dir, just provide the full paths.
    Do a file test to make sure the script can see the file.
    Use the File::Copy module instead of the system call.
    http://search.cpan.org/~nwclark/perl...b/File/Copy.pm

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    So far no luck

    Thanks for the advice. I tested the file prior to calling "system", as follows:

    errout("File not found") unless -e 'c:\Contracts\FieldData\3617_CROSS_BEND_RD_PLANO.txt'; # DEBUG

    Actually, this file was created by the same script, and properly "closed". This means that the directory is accessible all right, and the test above confirms that the file is seen by the code. I even changed the system call to

    my @comargs = ('DEL', 'c:\Contracts\FieldData\3617_CROSS_BEND_RD_PLANO.txt');
    system(@comargs) == 0 or errout("system @comargs failed: $?:$!");

    just to avoid supplying the second argument required by the COPY command. Unfortunately, it failed again:

    Error: system DEL c:\Contracts\FieldData\3617_CROSS_BEND_RD_PLANO.txt failed: 65280:No such file or directory

    I don't know, perhaps, the error refers to the Windows command itself rather than to the file? Actually, I will be running another, non-OS, executable on the file. At this stage, I just want to make sure that system calls work.

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Does the script work correctly when run from the command line? If so, then it's an access rights issue where the web server user account doesn't have rights to the directory and/or file.

  • #5
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    My script works .. kinda

    Yes, everything works fine when executed from the command line. Anyway, I decided to run the real code:

    errout("Executable pdf-FieldMerge not found") unless -e '\Program Files\Ovis\pdf-FieldMerge\pdf-FieldMerge.exe';

    my $exedir = '\Program Files\Ovis\pdf-FieldMerge';
    unless(chdir $exedir) {
    errout("Cannot cd to $exedir: $!");
    exit;
    }

    my @comargs = ('pdf-FieldMerge', '-s', '\Contracts\Res_SF_TREC_Form.pdf', "\\Contracts\\ContractFiles\\$fnamec", 'null', 'null', '-d', "\\Contracts\\FieldData\\$fname");
    system(@comargs) == 0 or errout("system @comargs failed: $?:$!");

    When I ran this code, I received the following error message:

    Error: system pdf-FieldMerge -s \Contracts\Res_SF_TREC_Form.pdf \Contracts\ContractFiles\3617_CROSS_BEND_RD_PLANO.pdf null null -d \Contracts\FieldData\3617_CROSS_BEND_RD_PLANO.txt failed: 256:Bad file descriptor

    but pdf-FieldMerge actually worked! I got the results I expected. I removed the error output, so the last line now reads

    system(@comargs);

    What does 'Bad file descriptor' means, by the way, in this context?

    Thanks again for your help.

  • #6
    smd
    smd is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,

    Sorry for talking to an old thread, but I had a similar problem and just wanted to share my findings. I used just perl on win XP (no cgi) but had the same problem: for example, I had something like (in a bigger script not done by me):
    Code:
    $syscmd = "latex.exe test.tex";
    system($syscmd) or die(" failed: $?:$!");
    running this, I too would get "Bad file descriptor" ... It is described elsewhere on the net (like in
    http://www.perlmonks.org/?node_id=75450)

    - there were better, but unfortunately I lost the links. Basically what I learned, is that if you pass a string to system(), it passes it down to the command prompt as sort of a filename, not a command - 'DOS' thinks "latex.exe test.tex" is a file, and it cannot find it (and hence "Bad File Descriptor"?). Thus, as the link above notes, one should pass the command and the parameters to the system() call as an array:

    Code:
    system("latex.exe", "test.tex") or die(" failed: $?:$!");
    However, for some reason, this failed for me too, until I tried:

    Code:
    system(cmd, "/c", "latex.exe", "test.tex" ) or die(" failed: $?:$!");
    Then the actual command does get executed... In fact, I first tried system(start, "/wait", ...) instead of system(cmd, "/c", ...) - and that works too, except it opens a new command window...

    Cheers

  • #7
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    system(cmd, "/c", "svnadmin dump","c:\\csvn\\data\\repositories\\test3",">dump3.file") or die(" failed: $?:$!");

    works in my Win2007 system.

    I use it to run SVN system commands.

    have also take care of the slashes of paths.

    Quote Originally Posted by smd View Post
    Hi there,

    Sorry for talking to an old thread, but I had a similar problem and just wanted to share my findings. I used just perl on win XP (no cgi) but had the same problem: for example, I had something like (in a bigger script not done by me):
    Code:
    $syscmd = "latex.exe test.tex";
    system($syscmd) or die(" failed: $?:$!");
    running this, I too would get "Bad file descriptor" ... It is described elsewhere on the net (like in
    http://www.perlmonks.org/?node_id=75450)

    - there were better, but unfortunately I lost the links. Basically what I learned, is that if you pass a string to system(), it passes it down to the command prompt as sort of a filename, not a command - 'DOS' thinks "latex.exe test.tex" is a file, and it cannot find it (and hence "Bad File Descriptor"?). Thus, as the link above notes, one should pass the command and the parameters to the system() call as an array:

    Code:
    system("latex.exe", "test.tex") or die(" failed: $?:$!");
    However, for some reason, this failed for me too, until I tried:

    Code:
    system(cmd, "/c", "latex.exe", "test.tex" ) or die(" failed: $?:$!");
    Then the actual command does get executed... In fact, I first tried system(start, "/wait", ...) instead of system(cmd, "/c", ...) - and that works too, except it opens a new command window...

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •