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

R

Random Task

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
 
R

Random Task

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
 
P

Paul Lalli

Random said:
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
 
B

Brian McCauley

Paul said:
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.
 
A

A. Sinan Unur

Random said:
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
 
P

Paul Lalli

Brian said:
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
 
P

Paul Lalli

A. Sinan Unur said:
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
 
D

Dr.Ruud

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.
 
A

A. Sinan Unur

A. Sinan Unur wrote: ....

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
 
R

Random Task

Random said:
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 ...
 
S

Sherm Pendley

Dr.Ruud said:
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--
 
J

Joe Smith

Paul said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Java calling .NET exec 3
use of exec() 12
PID of exec 34
PID of exec 0
Cannot get exec syntax correct 6
interpolate system() or exec() 4
Ruby's Kernel::exec (and system and %x) 28
Exec and command 7

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top