Syntax_Error
Syntax_Error

Reputation: 6220

system calls in C

I have a function in C that calls another software to execute and generate a file then its manipulates the data e.g.

void main()
{
function();
//manipulate data in output.txt
}    
void execute()
{
system("./test input.txt output.txt");
}

for some reason the output.txt file is not being generated by full...how does the system call work? will execute return to main before system call ends? if yes how can I solve this? Im working on ubuntu using gcc

Upvotes: 0

Views: 14707

Answers (1)

Andrew
Andrew

Reputation: 2568

  1. Check the result of system() ALWAYS. Ensure that it executed successfully(ie. returns 0 or whatever is a successful result for 'test')
  2. When system executes it runs through /bin/sh (on unix/linux anyway). However since you're specifying it with './test' make sure that you're operating in the working directory that you THINK you are. Complex systems(and poorly designed ones) change directories like underwear.

Upvotes: 6

Related Questions