Home > Archive > PERL Beginners > August 2004 > Return values of "system"
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Return values of "system"
|
|
| Prasanna Kothari 2004-08-03, 9:02 am |
| Hi,
I have a code snippet like:
<<CUT>>
@args = "/bin/vi /tmp/t1.txt";
$val = system(@args);
if($val != 0) {
if($val == -1) {
print "Execution failed $OS_ERROR\n";
exit;
} else {
print "Program exited with error code $? << 8\n";
exit;
}
}
Notice that the code snippet is executing vi with a file and hence
editor opens up the file. After typing if I give a wrong vi command for
eg: "W" instead of "w"; $val gets a value greater than zero(256) and
hence the else part gets executed. The number of times I give a wrong vi
command , the return value gets incremented by 256.
This snippet is part of a larger program, which opens a editor and asks
the user to type in, after the user saves the file contents and exits
out of the editor, the program reads the contents of the file for
further processing.
Is there a way to overcome this situation?
Thanks in advance
Prasanna
| |
| Jose Alves De Castro 2004-08-04, 8:58 am |
| On Mon, 2004-08-02 at 14:52, Prasanna Kothari wrote:
> Hi,
Hi
> [... code ...]
I have tried your code and it works...
> Notice that the code snippet is executing vi with a file and hence
> editor opens up the file. After typing if I give a wrong vi command for
> eg: "W" instead of "w"; $val gets a value greater than zero(256) and
This does not happen to me :-|
> hence the else part gets executed. The number of times I give a wrong vi
> command , the return value gets incremented by 256.
> This snippet is part of a larger program, which opens a editor and asks
> the user to type in, after the user saves the file contents and exits
> out of the editor, the program reads the contents of the file for
> further processing.
>
> Is there a way to overcome this situation?
Are you sure the problem is in that piece of code? Have you tried
separating it from the rest of code and test it alone? Because that's
what I've done and it works... $val has always been 0 :-|
> Thanks in advance
HTH,
jac
> Prasanna
>
>
>
>
>
--
José Alves de Castro <cog@cpan.org>
http://natura.di.uminho.pt/~jac
|
|
|
|
|