PROCESS输出的命令

PROCESS输出的命令

本文介绍了在标准输出上显示EXIRTE_PROCESS输出的命令,例如dir或echo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想直接在程序运行时直接在stdout上看到由 EXECUTE_PROCESS 命令启动的命令的输出。

I would like to directly see the output of a command started by the EXECUTE_PROCESS command on stdout while the program is running.

我有以下测试CMakeLists.txt文件

I have the following test CMakeLists.txt file

PROJECT(TEST)
cmake_minimum_required(VERSION 2.8)

EXECUTE_PROCESS(COMMAND dir)

从命令行运行时,它会生成

When run from the commandline it produces this

D:\tmp\testCMake\_build>"c:\Program Files (x86)\CMake 2.8\bin\cmake.exe" .
-- Configuring done
-- Generating done
-- Build files have been written to: D:/tmp/testCMake/_build

我想直接在控制台上查看 dir 的输出。

I would like to see the output from dir directly on the console.

我知道我可以使用 OUTPUT_VARIABLE ERROR_VARIABLE 参数捕获输出。但这会在命令运行结束时提供结果。

I know I can capture the output using the OUTPUT_VARIABLE and ERROR_VARIABLE arguments. But, that provides the result at the end of the command run.

根据文档,输出通常应通过

According to the documentation the output should normally be passed through

我在Windows Vista上使用CMake 2.8.3

I am using CMake 2.8.3 on Windows Vista

推荐答案

尝试:

execute_process(COMMAND cmd /c dir)

。 dir是内置的shell命令。 execute_process需要* .exe文件名,因为它是COMMAND之后的第一个参数。 (或者PATH中提供了一些exe文件。)

instead. 'dir' is a built-in shell command. 'execute_process' expects a *.exe file name as it's first argument after COMMAND. (Or some exe available in the PATH.)

实际上,如果您尝试挖掘并找出原始的execute_process调用有什么问题...

In fact, if you try to dig in and find out what's wrong with your original execute_process call...

execute_process(COMMAND dir RESULT_VARIABLE rv)
message("rv='${rv}'")

...您将获得以下输出:

...you'll get this output:

rv='The system cannot find the file specified'

如果将 dir传递给WIN32 CreateProcess调用,几乎可以得到什么。

Which is pretty much what you'd get if you passed "dir" to the WIN32 CreateProcess call.

这篇关于在标准输出上显示EXIRTE_PROCESS输出的命令,例如dir或echo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 11:17