system() produces error.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jamie Ruff

    system() produces error.

    I am having problems with making system calls on Windows under Cygwin
    that involve the use of redirection operators and pipes. For example,
    the line below will cat two files, but the next command will not
    append the first file to the end of the second as expected and issues
    the error "Can't spawn "cmd.exe": No such file or directory at line
    x". If I issue the append command manually on the command line, then
    it works fine.

    system("cat file1 file2"); # works fine
    system("cat file1 >> file2"); # where is cmd.exe?

    Since the first command works, I assume that the path to 'cmd.exe' is
    set correctly within the program as system always uses cmd.exe to run
    commands.

    If I use ``'s, then I do not get the error, but the command still does
    not execute.

    One possible explanation, is that since I am using Cygwin on Windows
    to allow the script to run UNIX style commands, Perl may be having
    problems with that. The question being how do I test for this?
  • Godzilla

    #2
    Re: system() produces error.

    Jamie Ruff wrote:

    (snipped)
    [color=blue]
    > the error "Can't spawn "cmd.exe": No such file or directory at line[/color]
    [color=blue]
    > If I issue the append command manually on the command line, then
    > it works fine.[/color]

    I am curious to read your syntax for appending from a command line.

    [color=blue]
    > system("cat file1 >> file2"); # where is cmd.exe?[/color]

    That is the same as,

    copy file1>>file2

    Which will cop a system error, "File cannot be copied onto itself"

    You are trying combine file1 and file2 then write the results to file1.

    copy file1+file2 file3

    Note that will append a \x1a line ending to your file3 print.


    system ("type file1>>file2");

    Do not use a die with that syntax when using Perl.


    What command line syntax are you using which successfully
    appends one file to another file?


    Purl Gurl

    Comment

    • Jamie Ruff

      #3
      Re: system() produces error.

      > What command line syntax are you using which successfully[color=blue]
      > appends one file to another file?
      >
      >
      > Purl Gurl[/color]

      I am using the UNIX command that is available through cygwin. For
      example, if I have these two files:

      file1.txt
      Only line of file 1.

      file2.txt
      Only line of file 2.

      and type in a cmd window with the cygwin\bin path set properly the
      following:
      cat file1.txt >> file2.txt

      file2.txt will now look like this:

      file2.txt
      Only line of file 2.
      Only line of file 1.

      which is what I am looking for (this is what I tried manually to prove
      to myself that I was not going insane or doing something stupid). I
      do not want to use the DOS 'type' command because I eventually want to
      port this to run directly on UNIX without having to do any recoding.
      The problem appears to be using any redirection or pipes in a system
      command when that system is making use of the cygwin binaries on a
      Windows system.

      Comment

      • Purl Gurl

        #4
        Re: system() produces error.

        Jamie Ruff wrote:
        [color=blue]
        > Purl Gurl wrote:[/color]
        [color=blue]
        > I am using the UNIX command that is available through cygwin. For
        > example, if I have these two files:[/color]

        No, you are using emulation of Unix commands. Regardless
        of which emulated Unix commands you invoke, it is your
        Win32 system which performs the tasks.

        Set an Environment Path to your cygwin in your Perl script,
        then run your commands. If this fails, use a full path
        to your cygwin executable. Reads you are invoking a
        Perl script which is outside the path for cygwin.

        Possibly, you do not have Perl configured correctly for
        use with cygwin.

        There are known issues with cygwin. It is a nice program
        but for many circumstances, cygwin causes more problems
        than are resolved.






        Purl Gurl

        Comment

        • Joe Smith

          #5
          Re: system() produces error.

          Jamie Ruff wrote:
          [color=blue]
          > system("cat file1 file2"); # works fine
          > system("cat file1 >> file2"); # where is cmd.exe?
          >
          > Since the first command works, I assume that the path to 'cmd.exe' is
          > set correctly within the program as system always uses cmd.exe to run
          > commands.[/color]

          No, it does not. Check the docs for system() again.

          For simple command strings, like the first one, perl executes the
          other program itself. Only for command strings with meta characters
          (such as ">>") will perl use a shell.

          It appears that you are not running the version of perl you think you are.

          C:\>\cygwin\bin \perl -MConfig -le "print $^X,' ',$Config{sh}"
          /usr/bin/perl /bin/sh
          C:\>perl -MConfig -le "print $^X,' ',$Config{sh}"
          C:\Perl\bin\per l.exe cmd /x /c

          As you can see, the Windows native version of perl.exe uses "cmd"
          and the cygwin version of perl uses "/bin/sh".

          Are you sure you're running cygwin's /usr/bin/perl and not the
          DOS C:\Perl\bin\per l.exe when it gives you problems?
          -Joe

          Comment

          • Joe Smith

            #6
            Re: system() produces error.

            Purl Gurl wrote:
            [color=blue]
            > There are known issues with cygwin. It is a nice program
            > but for many circumstances, cygwin causes more problems
            > than are resolved.
            >
            > http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html[/color]

            That document is out-of-date. While what it says is true:
            The problem basically boils down to the fact that cygwin
            attempts to offer a UNIX like file-system structure where
            absolute path names start with / instead of a windows
            style (e.g. c:). ActiveState's perl does not understand
            this UNIX style names.
            The solution is to use the version of perl that comes with
            cygwin instead of ActiveState's perl when running under cygwin.
            [color=blue]
            > http://www.xav.com/perl/lib/Pod/perlcygwin.html[/color]

            Note where it says "snapshots that were expected to stabilize early
            in 2000" and refers to perl5.005_62 as the newest. Another
            out-of-date document.

            -Joe

            Comment

            • Purl Gurl

              #7
              Re: system() produces error.

              Joe Smith wrote:
              [color=blue]
              > Purl Gurl wrote:[/color]

              (snipped)
              [color=blue][color=green]
              > > http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html[/color][/color]
              [color=blue]
              > That document is out-of-date. While what it says is true:[/color]

              Then that document is not out of date. You are
              contradicting yourself.

              [color=blue][color=green]
              > > http://www.xav.com/perl/lib/Pod/perlcygwin.html[/color][/color]
              [color=blue]
              > Another out-of-date document.[/color]

              Information in that document holds true, today.

              You need to pay more attention to what is written,
              rather than document dates.


              Purl Gurl

              Comment

              • Joe Smith

                #8
                Re: system() produces error.

                Purl Gurl wrote:
                [color=blue][color=green][color=darkred]
                >>>http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html[/color][/color][/color]
                [color=blue][color=green]
                >>That document is out-of-date. While what it says is true:[/color]
                >
                > Then that document is not out of date. You are
                > contradicting yourself.[/color]

                The document is out-of-date because it was implying
                that the only version of Perl for Windows is ActiveState's.
                Using the cygwin version of Perl under cygwin does not
                have the problems that the ActiveState version of perl
                has under cygwin.
                [color=blue]
                >[color=green][color=darkred]
                >>>http://www.xav.com/perl/lib/Pod/perlcygwin.html[/color][/color]
                >[color=green]
                >>Another out-of-date document.[/color]
                >
                > Information in that document holds true, today.[/color]

                So you're saying that version 5.005_62 is the newest?
                -Joe

                Comment

                • Purl Gurl

                  #9
                  Re: system() produces error.

                  Joe Smith wrote:
                  [color=blue]
                  > Purl Gurl wrote:[/color]

                  (snipped)

                  Rather amusing you boys are so insecure, so lacking in
                  self-confidence, you are psychotically driven to have
                  the last word no matter how inane is your last word.


                  Purl Gurl

                  Comment

                  • pete

                    #10
                    Re: system() produces error.

                    Purl Gurl <purlgurl@purlg url.net> wrote in news:40F9377D.6 E6889B9
                    @purlgurl.net:
                    [color=blue]
                    > Joe Smith wrote:
                    >
                    > Rather amusing you boys are so insecure, so lacking in
                    > self-confidence, you are psychotically driven to have
                    > the last word no matter how inane is your last word.
                    >
                    >
                    > Purl Gurl[/color]

                    And I get the last word of the thread, hurray!
                    My congratulations to the most well known Perl programmer in the Perl
                    community for the second place spot.






                    Comment

                    • Nathalie

                      #11
                      Re: system() produces error.


                      I too have the error "Can't spawn "cmd.exe": No such file or director
                      at line "


                      If I issue the command manually on the command line, then
                      it doesn't work, but the error "Can't spawn "cmd.exe": No such file o
                      directory at line" doesn't appear.

                      In either case, a window opens and tells me that the program UNKNOW
                      that I've called cannot work properly and that it has to be closed.

                      My syntax is
                      system "C:\\Progra m Files\\Programm es LINKAGE\\unknow n";

                      I know that the UNKNOWN program works properly, because it works on a
                      other data set.

                      I call my programs in a dos prompt on Windows.

                      Thank yo


                      -
                      Nathali
                      -----------------------------------------------------------------------
                      Posted via http://www.codecomments.co
                      -----------------------------------------------------------------------

                      Comment

                      • thundergnat

                        #12
                        Re: system() produces error.

                        Nathalie wrote:[color=blue]
                        > I too have the error "Can't spawn "cmd.exe": No such file or directory
                        > at line "
                        >
                        >
                        > If I issue the command manually on the command line, then
                        > it doesn't work, but the error "Can't spawn "cmd.exe": No such file or
                        > directory at line" doesn't appear.
                        >
                        > In either case, a window opens and tells me that the program UNKNOWN
                        > that I've called cannot work properly and that it has to be closed.
                        >
                        > My syntax is
                        > system "C:\\Progra m Files\\Programm es LINKAGE\\unknow n";
                        >
                        > I know that the UNKNOWN program works properly, because it works on an
                        > other data set.[/color]

                        This is only peripherally perl related.
                        In the DOS command window, when calling parameters have a space in them,
                        you need to enclose them in double quotes. Try something like:

                        system "\"C:\\Prog ram Files\\Programm es LINKAGE\\unknow n\"";

                        or even better:

                        system '"C:\Program Files\Programme s LINKAGE\unknown "';



                        This news group is doesn't exist. Please use comp.lang.perl. misc in the
                        future.

                        Comment

                        • nobull@mail.com

                          #13
                          Re: system() produces error.

                          Nathalie <Nathalie.1bgzp o@mail.codecomm ents.com> wrote in message news:<Nathalie. 1bgzpo@mail.cod ecomments.com>. ..[color=blue]
                          > I too have the error "Can't spawn "cmd.exe": No such file or directory
                          > at line "
                          >
                          >
                          > If I issue the command manually on the command line, then
                          > it doesn't work, but the error "Can't spawn "cmd.exe": No such file or
                          > directory at line" doesn't appear.
                          >
                          > In either case, a window opens and tells me that the program UNKNOWN
                          > that I've called cannot work properly and that it has to be closed.
                          >
                          > My syntax is
                          > system "C:\\Progra m Files\\Programm es LINKAGE\\unknow n";[/color]

                          If you had typed the contents of that string at the command prompt
                          manually what would have happend?

                          You'd have got an error because windows would fail to find
                          C:\program.exe (or C:\program.cmd or ...)

                          You need to protect the spaces in the filename exactly as you would if
                          you typed the command at the prompt or you must use the list form of
                          system(). Note I don't think you can use the list form without
                          passing at least one argument so if it is important that you all
                          unknown.exe with no arguments then the list form is not an option.

                          This nresgroup does not exist (see FAQ). Please do not reactivate
                          long-dormant threads here.
                          [color=blue]
                          > I know that the UNKNOWN program works properly, because it works on an
                          > other data set.
                          >
                          > I call my programs in a dos prompt on Windows.
                          >
                          > Thank you[/color]

                          Comment

                          Working...