我有一个粒子系统程序,它在每次迭代中生成一个带粒子坐标的.dat
文件。最终目标是通过具有不同参数的脚本多次运行程序。因此,我试图以一种方式设置我的程序,对于每次运行,所有相关数据都将存储在一个文件夹中。不正确地使用系统()调用?
我要做的就是以从.dat
文件PNGs
与Gnuplot
,叫ffmpeg
创建一个视频输出的PNGs
的,使用WinRAR
压缩.dat
文件,最后清理,删除所有的中间文件。这工作,当我在工作目录中。
现在我尝试创建一个新的目录,并在那里做同样的事情。我的代码:
// Load the proper library to use chdir() function
#ifdef _WIN32
#include <direct.h>
#elif defined __linux__ || defined __APPLE__&&__MACH__
#include <unistd.h>
#endif
// Make output directory and change working directory to new directory
ostringstream dirCommand;
dirCommand << "mkdir " << folderName_str;
system(dirCommand.str().c_str());
const char* test = folderName_str.c_str();
#ifdef _WIN32
if(_chdir(test))
{
printf("Unable to locate the directory: %s\n",test);
return;
}
#elif defined __linux__ || defined __APPLE__&&__MACH__
if(chdir(test))
{
printf("Unable to locate the directory: %s\n",test);
return;
}
#endif
else
printf("Created output directory...\n");
已经是这部分,我知道会有反对意见。我已经广泛地观察了SO,许多人赞成Windows的SetCurrentDirectory()
,或者他们对使用system()
持怀疑态度。在我的防守,我是新手程序员,我的知识实在有限......
现在,当我试图让视频与FFMpeg
,然后RAR /焦油我的文件:
// Make video
std::cout << "Generating Video..." << endl;
ostringstream command;
command << "ffmpeg -f image2 -r 1/0.1 -i output_%01d.png -vcodec mpeg4 " << videoName_str << ".avi -loglevel quiet";
std::system(command.str().c_str());
// Clean Up!
std::cout << "Cleaning up!" << endl;
ostringstream command2;
#ifdef _WIN32
command2 << "rar -inul a " << videoName_str << ".rar *.dat settings.gp loadfile.gp";
#elif defined __linux__ || defined __APPLE__&&__MACH__
command2 << "tar cf " << videoName_str << ".tar *.dat settings.gp loadfile.gp";
#endif
std::system(command2.str().c_str());
我得到Win/Linux中非常不同的行为。
Win 7 x64,Visual Studio 2010/12
在Windows中,该文件夹已创建。 .dat
文件生成正确,gnuplot
也绘制PNGs
。当ffmpeg
被调用时,没有任何反应。没有从FFMpeg
或任何错误消息。 WinRAR
也是如此。也许,最后一件事,我可以使用免费的7z
命令行工具!
Linux Mint的14 64,Qt的4.8.1
奇怪的是,该行为是由该Windows的反转。只要第一个.dat
文件被更改,就会更改目录。这就好像我为我的文件生成对fprintf()
所做的每个后续调用都不起作用,或者在某处丢失了。 Gnuplot
作品,如ffmpeg
和tar
!!
我真的很困惑。任何帮助将非常感激。
我认为只要编写shell脚本来做这件事会更好。您可能需要为每个平台单独使用一个,但是谁在乎 - 现在获得的条件编译相当于相同的东西。 –
谢谢!我真的沉迷于此。但要带回家的信息是学习如何管理我的错误。我必须更好地预测无效的用户输入。 – Dima1982