简体   繁体   English

在C ++中执行Windows命令并将输出重定向到本地字符串

[英]Execute windows command inside C++ and redirect the output to local string

I'm trying to execute 我正在尝试执行

    which file.exe

within c++ and want to redirect the result to a string to make further processes 在c ++中,并且希望将结果重定向到字符串以进行进一步处理

I've tried system and CreateProcess but this executes command and redirects the results to stdout or a file. 我已经尝试了system和CreateProcess,但是这会执行命令并将结果重定向到stdout或文件。

but how do I get this result within a local string ? 但是如何在本地字符串中得到此结果?

Thanks 谢谢

重定向到管道(使用CreateProcess ),并将管道末端读取到本地字符串中。

我建议使用_popen (在Unix上为popen)。

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

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