Tolgar
asked on
How can we make a system call within Perl
Hi,
How can we make a system call within Perl?
For example, I do the following in the command line. Now I wanna make the same in Perl.
Thanks,
How can we make a system call within Perl?
For example, I do the following in the command line. Now I wanna make the same in Perl.
java -jar myFirstcode.java input1 input2
Thanks,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The exit status is available in $?
$output = `java -jar myFirstcode.java input1 input2`;
$program_retval = $? >> 8;
ASKER
I did this. I think it is same as your first suggestion:
Thanks,
system("java -jar myFirstcode.java input1 input2");
But I didn't understand your second reply. Is it related with the second part of my question which is about catching exceptions?Thanks,
Hi.
Using system is fine, too.
Yes, my second note had to do with how to examine the $? variable to determine the status of the command. It applies to the system function as well as to the backtick operator.
Using system is fine, too.
Yes, my second note had to do with how to examine the $? variable to determine the status of the command. It applies to the system function as well as to the backtick operator.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The advantage to backticks is that you can capture the output of the call. If you don't need to do that, I would use system.
@wilcoxon is the expert on this. What he say.
ASKER
Both solutions are very good but I picked wilcoxon's solution as best becasue it covers both questions and two different methods in a very descriptive way. But as I said both solutions are great.
Thanks,
Thanks,
ASKER
Can you please send me an example code that is very safe in handling this exception?
Thanks,