in reply to trouble with system calls

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.

Replies are listed 'Best First'.
Re: Re: trouble with system calls
by wiza (Initiate) on Feb 10, 2004 at 07:21 UTC
    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!
      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).

      The system call fails? You don't check.

      My guess is tthat you need to use "./svm_classify" instead of just "svm_classify" because, well, . normally is not in $PATH.

      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.