Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

popen is in the standard C library See the man page

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top