开发者

system call does not work as in the command line

Ok I have two programs, and one calls another using 开发者_如何学Goexecutable from another. I am running it on Ubuntu terminal

This is folder structure in place

.../src/pgm1/pgm1 .../src/pgm0/pgm0

pgm1 and pgm0 are executables.

This is how I call the other executable

char cmd[1000]; string path = "/home/usr/src/"; // call pgm0 for each instance... sprintf( cmd, "../pgm0/pgm0 xRes 400 xRes 400 inFile tmp_output/%s.%04d.sc > tmp_output/%s.%04d.ppm", g_outFile.c_str(), ti, g_outFile.c_str(), ti); cout << cmd << endl; system (cmd); ....

I looked over and the cmd is generated properly: ../pgm0/pgm0 yRes 400 xRes 400 inFile tmp_output/sph0.0000.sc > tmp_output/sph0.0000.ppm

So if I run this command from command line it works perfectly well.

If I run it using system call it hangs and fails to parse input file sph0.0000.sc I tried adding full path (hence path variable up)

But still no luck.

Any ideas why would this work from command line and not from system call within another executable...

Just to make it clear it works from command line in folder pgm1.

Thanks


You are using > which means something to many shells, but I suspect not to system. Try this:

snprintf( cmd, sizeof cmd,
    "/usr/bin/bash -c '../pgm0/pgm0 xRes 400 xRes 400"
    " inFile tmp_output/%s.%04d.sc > tmp_output/%s.%04d.ppm'",
    g_outFile.c_str(), ti, g_outFile.c_str(), ti);

And let us know how that goes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜