Ashish
Ashish

Reputation: 11

mulitple parameters in perl system function for windows

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

Answers (3)

ikegami
ikegami

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);

Option 1

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.

Option 2

Use the correct syntax for the local shell.

if ($O eq 'MSWin32') {
   system('echo 1 & echo 2');
} else {
   system('echo 1 ; echo 2');
}

Option 3

Call system twice.

system('echo 1');
system('echo 2');

Upvotes: 2

Programmer
Programmer

Reputation: 475

Is this what you are trying

$a=" echo wasssup people";
$b=" echo hi guys";
system("$a"."$b");

Upvotes: -1

mpapec
mpapec

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

Related Questions