windows - 如何输出一个持续激活的 CMD
问题描述
我正在运行一个打开 CMD 并通过 API 服务连接的应用程序。一整天,新的东西都会出现在 CMD 中,我想将该信息导出到某个地方的 txt 文件中,并且每次出现新的东西时都会附加到同一个文件中,或者创建一个新文件。没关系
App.exe > /file.txt 并没有真正起作用
解决方案
重定向示例
command > filename # Redirect command output to a file (overwrite)
command >> filename # APPEND into a file
command 2> filename # Redirect Errors from operation to a file(overwrite)
command 2>> filename # APPEND errors to a file
command 2>&1 # Add errors to results
command 1>&2 # Add results to errors
command | command # This is the basic form of a PowerShell Pipeline
# In PowerShell 3.0+
command 3> warning.txt # Write warning output to warning.txt
command 4>> verbose.txt # Append verbose.txt with the verbose output
command 5>&1 # Writes debug output to the output stream
command *> out.txt # Redirect all streams (output, error, warning, verbose, and debug) to out.txt
您没有显示任何关于如何为您的用例启动/使用 cmd.exe 的代码。这只是让人们试图帮助你,猜测。所以,重定向 cmd.exe,例如:
$MyOutputFile = C:\MyOutputFile.txt
Start-Process -FilePath c:\windows\system32\cmd.exe -ArgumentList '/c C:\YourCommand.bat' -Wait -NoNewWindow -RedirectStandardOutput $MyOutputFile
最后,因为你让我们猜测。如果您从 PowerShell 启动进程 A,但进程 A 反过来又启动进程 B,则由进程 A 来捕获或重定向进程 B 的输出。PowerShell 无法分如果进程 A 没有这样做,则捕获。
资源
推荐阅读
- .net-core - 使用 NLog 在 ASP .Net Core 5 Web API 中使用 Pomelo 提供程序登录到 MySql 数据库
- python - python plotly中x轴标题的方向
- postgresql - PostgreSQL 反义词
- node.js - 如何通过 cpanel 文件管理器安装 node.js 源代码
- css - ng serve 命令出错。./ 节点模块/@angular-devkit/build
- javascript - 如何将 React-mapbox-gl 约束到其容器?
- node.js - 以编程方式设置域 node.js 应用程序
- stm32 - 如何在 STM32 中禁用 STOP 模式
- python - 如何在 TOC(目录)之前插入段落
- android - 使用 Flutter 将图像上传到通用 Google Drive 帐户