简体   繁体   English

C ++-系统命令

[英]C++ - system command

I have a C++ program which is mainly used for video processing. 我有一个C ++程序,主要用于视频处理。 Inside the program, I am launching the system command in order to obtain pass the processed videos to some other binaries to postprocess them. 在程序内部,我正在启动system命令,以便将经过处理的视频传递给其他二进制文件以对其进行后处理。

I have a while loop towards infinite and I am launching the system command inside the loop every time. 我有一个转向无限的while循环,每次都在循环内启动系统命令。 The thing is that at a certain point I am receiving the -1 return code from the system command. 问题是,在某个时候,我将从system命令中接收-1返回代码。 What could be the reason for that? 可能是什么原因呢?

Inside the system command I am just calling a binary file with the adequate parameters from the main project. 在系统命令内部,我只是从主项目中调用带有适当参数的二进制文件。

The system command which I want to execute is actually a shell file. 我要执行的system命令实际上是一个shell文件。 In this file I am extracting the main feature from the video and passing them through a SVM model from a 3D party library in order to obtain the the desired classification. 在此文件中,我将从视频中提取主要功能,并将其通过3D参与者库中的SVM模型传递,以获得所需的分类。

./LiveGestureKernel ./Video ./SvmVideo
./mat4libsvm31 -l SvmVideoLabels < SvmVideo > temp_test_file
./svm-predict temp_test_file svm_model temp_output_file
cat < temp_output_file
rm -f temp_*

After a certain number of iterations through the while loop, it just won't execute the script file and I cannot figure out the reason for this. 在while循环中经过一定次数的迭代后,它只是不会执行脚本文件,而且我无法弄清其原因。 Thanks! 谢谢!

If you get -1 from the call to system() , you should first examine the contents of errno - that will most likely tell you what your specific problem is. 如果从对system()的调用中获得-1 ,则应首先检查errno的内容-这很可能会告诉您您的特定问题是什么。

The one thing to watch out for is that the return value from system is an implementation-defined one in the case where you pass it a non-NULL command, so it's possible that -1 may be coming from your actual executable. 需要注意的一件事是,如果您向其传递非NULL命令,则system的返回值是实现定义的值,因此-1可能来自您的实际可执行文件。

Your best bet in that case is to print out (or otherwise log) the command being executed on failure (and possibly all the time), so that you can check what happens with the same arguments when you execute it directly from a command line or shell. 在这种情况下,最好的选择是打印出(或以其他方式记录)在失败时(可能一直在执行)的正在执行的命令,以便当您直接从命令行或命令行执行命令时,可以检查使用相同参数发生的情况贝壳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM