in reply to Re: trouble with system calls
in thread trouble with system calls

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!

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

Re: (3) trouble with system calls
by bart (Canon) on Feb 10, 2004 at 07:44 UTC
    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.

Re: Re: Re: trouble with system calls
by Ao (Friar) on Feb 10, 2004 at 22:58 UTC
    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.