开发者

Executing external program via system() does not run properly

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 pat开发者_运维问答h...

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜