Exec/System call with spaces in exec path problem ...

Discussion in 'Perl Misc' started by Random Task, Dec 2, 2005.

  1. Random Task

    Random Task Guest

    Hi i am writing perl on windows ... i am having a hard time executing a
    path with spaces ... can someone help ?

    my $command = "C:\\Documents and Settings\\jgdon\\My Documents\\run.exe";

    system ("$command 1>C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    Thanks,
    Jim
    www.gomba.ca
    Random Task, Dec 2, 2005
    #1
    1. Advertising

  2. Random Task

    Random Task Guest

    Sorry here is the error message i am getting ...

    'C:\Documents' is not recognized as an internal or external command,
    operable program or batch file.


    Jim
    www.gomba.ca


    Random Task wrote:
    > Hi i am writing perl on windows ... i am having a hard time executing a
    > path with spaces ... can someone help ?
    >
    > my $command = "C:\\Documents and Settings\\jgdon\\My Documents\\run.exe";
    >
    > system ("$command 1>C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");
    >
    > Thanks,
    > Jim
    > www.gomba.ca
    Random Task, Dec 2, 2005
    #2
    1. Advertising

  3. Random Task

    Paul Lalli Guest

    Random Task wrote:
    > Random Task wrote:
    > > Hi i am writing perl on windows ... i am having a hard time executing a
    > > path with spaces ... can someone help ?
    > >
    > > my $command = "C:\\Documents and Settings\\jgdon\\My Documents\\run.exe";
    > >
    > > system ("$command 1>C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    >
    > Sorry here is the error message i am getting ...
    >
    > 'C:\Documents' is not recognized as an internal or external command,
    > operable program or batch file.


    [quoting fixed - post new replies *below* the existing text. Thank
    you]

    Fix this the same way you would if you were running the command from
    the command line, rather than from Perl: Enclose the name of the
    command in single quotes:

    system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    Paul Lalli
    Paul Lalli, Dec 2, 2005
    #3
  4. Paul Lalli wrote:

    > Fix this the same way you would if you were running the command from
    > the command line, rather than from Perl: Enclose the name of the
    > command in single quotes:
    >
    > system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");


    Single? Are you sure. What OS do you think the OP is using?

    This is, of course, as you point out, purely a question about the OS's
    CLI not related to Perl.
    Brian McCauley, Dec 2, 2005
    #4
  5. "Paul Lalli" <> wrote in
    news::

    > Random Task wrote:
    >> Random Task wrote:
    >> > Hi i am writing perl on windows ... i am having a hard time
    >> > executing a path with spaces ... can someone help ?
    >> >
    >> > my $command = "C:\\Documents and Settings\\jgdon\\My
    >> > Documents\\run.exe";
    >> >
    >> > system ("$command 1>C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    >>
    >> Sorry here is the error message i am getting ...
    >>
    >> 'C:\Documents' is not recognized as an internal or external command,
    >> operable program or batch file.

    >
    > [quoting fixed - post new replies *below* the existing text. Thank
    > you]
    >
    > Fix this the same way you would if you were running the command from
    > the command line, rather than from Perl: Enclose the name of the
    > command in single quotes:
    >
    > system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");


    I don't think the single quotes will help on windows.

    system(qq{"$command" 1 > C:\\JIMTEST.TXT 2 > C:\\JIMTEST.TXT});

    Often times, the list form of the system call is overlooked:

    perldoc -f system

    ... Note that argument processing varies depending on the number
    of arguments. If there is more than one argument in LIST, or if
    LIST is an array with more than one value, starts the program
    given by the first element of the list with arguments given by
    the rest of the list.

    In this particular case, the OP needs the shell re-direction
    functionality so I it would not help to call system with a list of
    arguments, but when shell functionality is not needed, the list form
    helps one avoid hassles with spaces in the path of the program being
    invoked -- arguments to the program would still have to be quoted,
    however.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 2, 2005
    #5
  6. Random Task

    Paul Lalli Guest

    Brian McCauley wrote:
    > Paul Lalli wrote:
    >
    > > Fix this the same way you would if you were running the command from
    > > the command line, rather than from Perl: Enclose the name of the
    > > command in single quotes:
    > >
    > > system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    >
    > Single? Are you sure. What OS do you think the OP is using?
    >
    > This is, of course, as you point out, purely a question about the OS's
    > CLI not related to Perl.


    Oops. Thanks for the correction. I'd forgotten about Windows bizarre
    handling of quotes.

    Paul Lalli
    Paul Lalli, Dec 2, 2005
    #6
  7. Random Task

    Paul Lalli Guest

    Purl Gurl wrote:
    > Paul Lalli wrote:
    >
    > > Oops. Thanks for the correction. I'd forgotten about Windows bizarre
    > > handling of quotes.

    >
    > Bizarre? Strikes me as perfectly intuitive.


    Your Honor, the prosecution rests.

    Paul Lalli
    Paul Lalli, Dec 2, 2005
    #7
  8. Random Task

    Paul Lalli Guest

    A. Sinan Unur wrote:
    > Often times, the list form of the system call is overlooked:
    >
    > In this particular case, the OP needs the shell re-direction
    > functionality so I it would not help to call system with a list of
    > arguments, but when shell functionality is not needed, the list form
    > helps one avoid hassles with spaces in the path of the program being
    > invoked -- arguments to the program would still have to be quoted,
    > however.


    They would? Why?

    C:\>perl -e"my $dir = 'C:/Documents and Settings/plalli';
    system('dir', $dir);"
    Volume in drive C has no label.
    Volume Serial Number is 8887-A813

    Directory of C:\Documents and Settings\plalli

    11/28/2005 03:11p <DIR> .
    11/28/2005 03:11p <DIR> ..
    10/17/2005 10:34a 3,436 .bash_history
    10/14/2005 07:32a <DIR> .cpan
    07/08/2005 10:03a <DIR> .emacs.d
    06/08/2005 01:22p <DIR> Application Data
    <snip>
    13 File(s) 30,078,232 bytes
    25 Dir(s) 34,015,353,344 bytes free

    Paul Lalli
    Paul Lalli, Dec 2, 2005
    #8
  9. Random Task

    Dr.Ruud Guest

    [meta] s_\\_/_g (was: Re: Exec/System call with spaces in exec path problem ...)

    Paul Lalli:

    > system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");


    I think it would be a nice default for Perl-lists if people would in
    their replies change the \\ to / in WinDOS pathnames.

    I wouldn't hesitate doing it even in the quoted text, serving a purpose
    of quoting.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Dec 2, 2005
    #9
  10. "Paul Lalli" <> wrote in news:1133553057.503229.104560
    @o13g2000cwo.googlegroups.com:

    > A. Sinan Unur wrote:

    ....
    >> arguments to the program would still have to be quoted,
    >> however.

    >
    > They would? Why?


    No they would not have to be. I ran into a couple of programs that had
    problems with spaces, and got in the habit of quoting arguments.

    Thanks for the correction.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 2, 2005
    #10
  11. Random Task

    Random Task Guest

    Random Task wrote:
    > Hi i am writing perl on windows ... i am having a hard time executing a
    > path with spaces ... can someone help ?
    >
    > my $command = "C:\\Documents and Settings\\jgdon\\My Documents\\run.exe";
    >
    > system ("$command 1>C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");
    >
    > Thanks,
    > Jim
    > www.gomba.ca



    qq{} fixed my problems ... cheers and thanks ...
    Random Task, Dec 2, 2005
    #11
  12. Re: [meta] s_\\_/_g

    "Dr.Ruud" <> writes:

    >> system(" '$command' 1> C:\\JIMTEST.TXT 2>C:\\JIMTEST.TXT");

    >
    > I think it would be a nice default for Perl-lists if people would in
    > their replies change the \\ to / in WinDOS pathnames.


    Although most function calls in Windows support the use of "/" path
    delimiters, the command shell does not. The use of "\\" is appropriate
    and necessary in this context.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Dec 2, 2005
    #12
  13. Random Task

    Joe Smith Guest

    Paul Lalli wrote:
    > A. Sinan Unur wrote:
    >
    >>Often times, the list form of the system call is overlooked:
    >>
    >>In this particular case, the OP needs the shell re-direction
    >>functionality so I it would not help to call system with a list of
    >>arguments, but when shell functionality is not needed, the list form
    >>helps one avoid hassles with spaces in the path of the program being
    >>invoked -- arguments to the program would still have to be quoted,
    >>however.

    >
    > They would? Why?
    >
    > C:\>perl -e"my $dir = 'C:/Documents and Settings/plalli';
    > system('dir', $dir);"


    Yes, they would, when the shell re-direction functionality is needed.

    C:\>perl -e "$dir='C:/Documents and Settings/jms';
    system(qq{dir $dir >dir.out});"
    Parameter format not correct - "Documents".

    -Joe
    Joe Smith, Dec 4, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Matthews
    Replies:
    4
    Views:
    657
    John B. Matthews
    Sep 12, 2008
  2. Roedy Green
    Replies:
    3
    Views:
    613
  3. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,573
    Jan C. Faerber
    Sep 10, 2009
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    862
    Jan C. Faerber
    Sep 10, 2009
  5. johkar
    Replies:
    2
    Views:
    2,850
    Mayeul
    Dec 10, 2009
Loading...

Share This Page