简体   繁体   English

使用参数执行.bat文件并读取C ++中的控制台输出

[英]Executing a .bat file with a parameter and reading the console output in C++

I have a batch file I need to execute, it has one parameter, If I were to run this script myself I would open up cmd and write 我有一个需要执行的批处理文件,它有一个参数,如果我自己运行此脚本,我将打开cmd并编写

lexparser.bat texfile.txt

and the output would then be printed to the console. 然后将输出打印到控制台。 I have shopped around and I have found some code which seems to be executing the file but I can't seem to extract the data being output, but I am unsure if this is correct. 我四处逛逛,发现一些似乎正在执行文件的代码,但是我似乎无法提取正在输出的数据,但是我不确定这是否正确。

QString pathDocument = qApp->applicationDirPath()+ "/stanford/lexparser.bat";
long result = (long)ShellExecute(0, 0, reinterpret_cast<const WCHAR*>(pathDocument.utf16()), 0, 0, SW_NORMAL);

I am using C++ as my language and I am also using the Qt Library to help me. 我使用C ++作为语言,也使用Qt库来帮助我。 I have limited programming ability so any help would be greatly appreciated 我的编程能力有限,所以我们将不胜感激

I would recommend using QProcess for doing that. 我建议使用QProcess来做到这一点。

See this question and its accepted answer for an example on how to do so. 有关如何操作的示例,请参见此问题及其公认的答案

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

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