在不同目录中并行执行系统命令

时间:2015-08-13 12:07:16

标签: c++ multithreading system c++98

我有一个可执行文件,可以在本地目录中读取和写入数据文件。我想在(例如)2个目录run1run2中使用不同的输入文件从C ++(不带C ++ 11)执行它。目前,我通过这种方式顺序完成:

boost::filesystem::path dir1("/path/to/my/workdir/run1");
boost::filesystem::path dir2("/path/to/my/workdir/run2");
boost::filesystem::current_path(dir1);
std::ofstream f1("data.txt");
f1 << 1.0 << " " << 2.0 << std::endl;
f1.close();
system("/path/to/the/executable");
std::ifstream r1("results.txt");
r1 >> x1;
boost::filesystem::current_path(dir2);
std::ofstream f2("data.txt");
f2 << 7.0 << " " << 3.0 << std::endl;
f2.close();
system("/path/to/the/executable");
std::ifstream r2("results.txt");
r2 >> x2;

我想在两个线程中运行它,但我看到boost::filesystem::current_path更改了所有线程的目录。然后我不知道如何正确地做到这一点......

0 个答案:

没有答案