Reputation: 11
I have one scneario where i have to execute one java program & for that i have to first set the class path & all those being invoked under single perl program. I am trying below command which doesn't work:
$command1="echo \" First command\"";
$command2="echo \" Second command\"";
system("$command1;$command2");
Above command works fine in LINUX but not in windows. Please help me in execution of this.
Upvotes: 1
Views: 74
Reputation: 386331
On most platforms,
system($shell_command);
means
system('sh', '-c', $shell_command);
On Windows, it means something closer to
system('cmd', '/x', '/c', $shell_command);
Keep using a bourne shell command, but explicitly specify a bourne shell is needed.
system('sh', '-c', 'echo 1 ; echo 2');
This isn't likely to work since the computer is not likely to have a bourne shell installed.
Use the correct syntax for the local shell.
if ($O eq 'MSWin32') {
system('echo 1 & echo 2');
} else {
system('echo 1 ; echo 2');
}
Call system
twice.
system('echo 1');
system('echo 2');
Upvotes: 2
Reputation: 475
Is this what you are trying
$a=" echo wasssup people";
$b=" echo hi guys";
system("$a"."$b");
Upvotes: -1
Reputation: 50657
If you want to use ;
between commands you have to invoke shell. This is alternative to ;
my @cmds =(
[ "echo", q{" First command"} ],
[ "echo", q{" Second command"} ],
);
system (@$_) for @cmds;
Upvotes: 1