tags:

views:

173

answers:

4

I try to call a program (ncbi blast, for those who need to know) from my code, via calling the command in a system() call.

If I execute the string directly in the shell, it works as intended, but if I try the same string via system(), the program returns much faster, without the intended results. The output file is created, but the file size is 0. The returned error code is also 0. I even tried appending "> output.log 2> error.log" but these files are not created.

I guess it has something to do with environment variables or the path...

The output file name is given via -o command line parameter, not output redirection.

I read something about the popen command being possibly better suited for my use-case, but I can not find it, which library is that from?

A: 

popen is in the standard C library See the man page

Chris Huang-Leaver
Thanks. Unfortunately, swapping system() with similar popen() calls did not produce the desired results. Using popen(), I tried to look at the possible error messages or any output, without success.
brandstaetter
Out of interest is there a reason you can't call the program directly ? I googled the program you mentioned, can't say it's my field!
Chris Huang-Leaver
If system() does not work then using popen() is not going to solve the problem. If it did work with system() then swapping to popen() would probably be preferable.
Martin York
@Chris: I'm writing a wrapper program which performs parameter sweeps ans stuff like that, calls blast multiple times.
brandstaetter
A: 

Some quick questions:

  • How do you execute in in the shell?
  • How do you execute in the system command?
  • What is the value returned by system?

Exact copy and paste from you terminal is preferable then an English description.

Martin York
+1  A: 

The most usual cause of such problems is incorrect environment variable setting in ones ~/.bashrc.

You should be able to see what ncbi is unhappy about by executing

$SHELL -c '<exact string you pass to system()>'

Another common way to debug this is with strace. Execute:

strace -fo /tmp/strace.out ./myProgram

and look in /tmp/strace.out for clues.

Employed Russian
I'll take a look at that, thanks!
brandstaetter
+1  A: 

Is there any reason that you do not want to fork and exec? This is a common idiom for executing one process from another.

ezpz
I'll try that, thanks.
brandstaetter