views:

102

answers:

1

Ok I have two programs, and one calls another using executable 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

+1  A: 

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.

John Zwinck