perl problem on windows

F

Fong Tsui

I have some difficulties to execute a command by using system() on
windows.

The command is like "$com1 -load $file1" and there are spaces in the
pathes of com1 and file1. For example, com1 and file1 both are located
in E:\Program Files. What I tried
1) system("$com1 -load $file1");
2) system("\"$com1\" -load \"$file1\");

The error message is "E:\Program is not recognized as an internal or
external command.

Does anybody know what did I do wrong and how to solve this?

Thank you very much,

Fong
 
D

dw

Fong Tsui said:
I have some difficulties to execute a command by using system() on
windows.

The command is like "$com1 -load $file1" and there are spaces in the
pathes of com1 and file1. For example, com1 and file1 both are located
in E:\Program Files. What I tried
1) system("$com1 -load $file1");
2) system("\"$com1\" -load \"$file1\");

The error message is "E:\Program is not recognized as an internal or
external command.

Does anybody know what did I do wrong and how to solve this?

have you tried:
system $com1, "-load", $file1
 
D

dw

mgarrish said:
Depends on what you're trying to run. That will work for a bat or exe file
but not another perl script (just as examples). My advice would be to avoid
the whole issue if you can (i.e., use e:\progra~1\ unless there is a good
reason why progra~1 will not correspond to the Program Files directory).

It seems to work for me. Could it be a setup issue? This is what I get:

D:\path with spaces>type main.pl
#!d:\perl\bin\perl5.8.0.exe

print "in $0\n";
$other_pgm = "d:\\path with spaces\\other script.pl";
@args = qw(arg1 arg2 arg3);
system $other_pgm, @args;
print "done with $0\n";

exit 0;


D:\path with spaces>type "other script.pl"
#!d:\perl\bin\perl5.8.0.exe

print "in $0\n";
$x = 0;
printf "%3d : %s\n", $x++, $_ foreach ($0, @ARGV);
print "done with $0\n";
exit 0;

D:\path with spaces>main.pl
in D:\path with spaces\main.pl
in d:\path with spaces\other script.pl
0 : d:\path with spaces\other script.pl
1 : arg1
2 : arg2
3 : arg3
done with d:\path with spaces\other script.pl
done with D:\path with spaces\main.pl

D:\path with spaces>
 
F

Fong Tsui

dw said:
It seems to work for me. Could it be a setup issue? This is what I get:

D:\path with spaces>type main.pl
#!d:\perl\bin\perl5.8.0.exe

print "in $0\n";
$other_pgm = "d:\\path with spaces\\other script.pl";
@args = qw(arg1 arg2 arg3);
system $other_pgm, @args;
print "done with $0\n";

exit 0;


D:\path with spaces>type "other script.pl"
#!d:\perl\bin\perl5.8.0.exe

print "in $0\n";
$x = 0;
printf "%3d : %s\n", $x++, $_ foreach ($0, @ARGV);
print "done with $0\n";
exit 0;

D:\path with spaces>main.pl
in D:\path with spaces\main.pl
in d:\path with spaces\other script.pl
0 : d:\path with spaces\other script.pl
1 : arg1
2 : arg2
3 : arg3
done with d:\path with spaces\other script.pl
done with D:\path with spaces\main.pl

D:\path with spaces>

Thanks for all inputs.
I've tried what suggested. If there is space within an arg, it doesn't work.
 
M

mgarrish

dw said:
It seems to work for me. Could it be a setup issue?

It should run from an 2000 or XP box that way (not sure anymore about NT),
but not any of the Win9x variants (I've never tried ME, but it's essentially
just 98 so I'd count it out too...). Win9x only have the file association
from an Explorer window (you always have to type "perl myscript.pl" from the
command line). You could get away with something like:

my $com = 'perl';
my $script = 'c:\program files\myscript.pl';

system $com, $script;

but you just need to watch out that you don't try and run "system $script"
on all Windows platforms and expect it to work. I know he didn't say what OS
he was using or what kind of program he was trying to run, but I just wanted
to mention that as a possible sticking point.

Matt
 

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

Members online

Forum statistics

Threads
474,121
Messages
2,570,712
Members
47,283
Latest member
hopkins1988

Latest Threads

Top