Re: trouble with system calls
by Zaxo (Archbishop) on Feb 10, 2004 at 06:28 UTC
|
Since you don't show code, I get a free guess. You call system with a single string and the shell is mangling the arguments. Definitely that.
| [reply] |
Re: trouble with system calls
by graff (Chancellor) on Feb 10, 2004 at 06:30 UTC
|
If you posted some code to show how you're using the system call -- maybe even try it on some basic task that's similar to the real one, but would be meaningful to us (e.g. "system('ls')" or some such), then we might be able to pinpoint something if you've got it wrong.
Short of that, we have to guess or ask about what you're doing. My first guess/question would be that perhaps the perl script is running with a different PATH, and can't find your C program. Try printing out "$ENV{PATH}", or simply specify the full path to the program in the system call.
Beyond that, I'm not sure what to guess... | [reply] |
Re: trouble with system calls
by ysth (Canon) on Feb 10, 2004 at 06:48 UTC
|
Seems like a C problem, not a perl one :)
Between the two ways of running it, is there some difference in the path? in the user it runs as? in the signals being caught/ignored? stdin/out/err being connected to a terminal? What does the program actually do? Does it print error messages? Are you actually calling the program you think you are? E.g. does running it standalone use a shell built-in while running it from perl uses a separate executable? What do you mean by "call it using a terminal"? Are you checking the return value from system()?
We need a little more to go on. | [reply] |
|
hello,
thanks so much. Please enlighten me about what could be wrong with the follwing :
chdir("/home/code/");
system("svm_classify zkereigenout.dat svmmodel.mod");
open(IN,"<svm_predictions");
@values = <IN>;
close(IN);
svm_classify is a program that produces an output file named svm_predictions. after my system call, i want to read the content of svm_predictions and assign it to the array named values. however, when I check the directory, svm_predictions does not exist... I made sure that the directory has the right permissions...thanks a lot!
| [reply] [d/l] |
|
| [reply] [d/l] [select] |
|
Check your return values:
chdir("/home/code/") or warn "chdir failed!\n";
system("svm_classify zkereigenout.dat svmmodel.mod") and warn "system
+failed: $!\n";
(Yes, that second line should have "and warn". system has it's return values kinda backward.)
Try system("echo foo>svm_predictions") in place of your system call and see if that works (or fails giving meaningful information). | [reply] [d/l] |
|
wiza, see zaxo's first response, I think he hit it on the head. You're calling system with only one argument and the shell is mangling it. Try again with
system("svm_classify","skereigenout.dat","svmmodel.mod");
and see if that works for you. You can also capture the return value of the system call as others have pointed out if you have any more troubles, but that also depends on if you wrote your C program to generate understandable error codes.
| [reply] [d/l] |
Re: trouble with system calls
by wiza (Initiate) on Feb 10, 2004 at 07:43 UTC
|
hello,
Please enlighten me about what could be wrong with the following :
chdir("/home/code/");
system("svm_classify zkereigenout.dat svmmodel.mod");
open(IN,"<svm_predictions");
@values = <IN>;
close(IN);
svm_classify is a program that produces an output file named svm_predictions. after my system call, i want to read the content of svm_predictions and assign it to the array named values. however, when I check the directory, svm_predictions does not exist... I made sure that the directory has the right permissions...thanks a lot!
janitored by ybiC: Reparented this (originally root) node into prior thread on same topic/question by same OP, and retitled accordingly | [reply] [d/l] |
|
use Cwd 'chdir';
#...
That will make chdir's effect be felt in your environment, where a shell is likely to look for the base for relative paths. You may find your missing 'svm_predictions' in your original start directory.
Update: ysth++ spotted a typo in code. Corrected.
| [reply] [d/l] |
|
Perhaps svm_classify is not found. Try
system("svm_classify zkereigenout.dat svmmodel.mod") == 0 or die "$? $
+!";
| [reply] [d/l] |
|
Are you running the script from the same directory as svm_classify If not maybe svm_classify cannot be found echo $PATH ,should tell you what all is included else use the full path of the program. It would be a good idea to use die as above in order to get an error message: does it say cannot find file or some such. HTH, chimni
| [reply] |