简体   繁体   English

如何抑制输出:: system(“del * .log”)出现在控制台中

[英]how to suppress to output of ::system(“del *.log”) from appearing in console

I am executing ::system("del *.log") in a win32 exe The above code prints the output to exe console. 我在win32 exe中执行::system("del *.log")上面的代码将输出打印到exe控制台。 How can i suppress the output being printed to console? 如何抑制输出到控制台的输出?

Use redirection and redirect stdout to the nul file: 使用重定向并将stdout重定向到nul文件:

::system("del *.log > nul")

"nul" is a hidden file present in all directories, and all it does is discard everything written to it. “nul”是一个存在于所有目录中的隐藏文件,它所做的就是丢弃写入它的所有内容。

This will still show errors (if there are any). 这仍然会显示错误(如果有的话)。 If you also want to suppress stderr, then: 如果你还想抑制stderr,那么:

::system("del *.log > nul 2>&1")

More info: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true 更多信息: http//www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx? mfr = true

On Windows, you should use SHFileOperation() instead. 在Windows上,您应该使用SHFileOperation() There are variable flags available, such as FOF_NO_UI , for suppressing visual output to the user. 有可用的变量标志,例如FOF_NO_UI ,用于抑制用户的视觉输出。 For example: 例如:

SHFILEOPSTRUCT FileOp = {0};
FileOp.wFunc = FO_DELETE;
FileOp.pFrom = "*.log\0";
FileOp.fFlags = FOF_FILESONLY | FOF_NO_UI;
SHFileOperation(&FileOp);

尝试这个:

::system("del *.log > nul") 

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

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