perl - Windows 命令提示符创建但不将输出重定向到文件
问题描述
我在这里看到的很多帖子都遇到了相反的问题。
我正在运行由其他人编写的 perl 命令,尽管使用了“>”命令,但输出都被强制显示在屏幕上。
Windows 清楚地知道我的意图,因为每次执行命令时都会创建全新的文件名,但日志文件的内容/大小为空且长度为 0 字节。
我的 perl 可执行文件与我的 perl 例程/.pl 文件位于不同的位置。
我尝试以管理员身份运行,而不是。
这不是程序有问题。我的一些同事执行得很好,他们的屏幕没有输出。
一般语法是:
F:\git\repoFolderStructure\bin>
F:\git\repoFolderStructure\bin>perl alog.pl param1 param2 commaSeparatedParam3 2020-12-17,18:32:33 2020-12-17,18:33:33 > mylogfile.log
>>>>>Lots and lots of output I wish was in a file
Also attempted in the directory with my perl.exe and gave the path to my repo folder's bin.
窗口是否有一些奇怪的东西可以创建/阻止 > 运算符的行为?
这是踢球者:我做得ipconfig > out.txt
很好,虽然......没有写到屏幕上。
感谢您提供有关我可以做些什么来尝试改变行为的任何提示!
解决方案
可能是在您捕获 STDOUT 时将输出发送到 STDERR。追加2>&1
以将两者捕获到同一文件中。
>perl -e"print qq{STDOUT\n}; warn qq{STDERR\n};" >stdout
STDERR
>type stdout
STDOUT
>perl -e"print qq{STDOUT\n}; warn qq{STDERR\n};" 2>stderr
STDOUT
>type stderr
STDERR
>perl -e"print qq{STDOUT\n}; warn qq{STDERR\n};" >stdout 2>stderr
>type stdout
STDOUT
>type stderr
STDERR
>perl -e"print qq{STDOUT\n}; warn qq{STDERR\n};" >both 2>&1
>type both
STDERR
STDOUT
请注意,2>&1
如果要合并两个流,则必须在重定向 STDOUT 之后进行。
推荐阅读
- python - 如何从 SIFT 算法生成的描述符中获取图像的关键点或像素坐标
- javascript - 从数组中检测圆交点
- javascript - 如何增加安全性以更新数据库 PHP 中的行
- java - StackPane 中另一个窗格下方的 JavaFX 鼠标事件
- informatica - libstdc++ 错误跟踪无法理解
- regex - Powershell 仅替换完全匹配的字符串
- http - 如何以角度发送新请求
- katalon-studio - 尝试在 Katalon Studio v6.3.3 中执行功能文件时出错 - NoClassDefFoundError
- c# - 无法在 Visual Studio 中使用正则表达式来删除 CSS 样式
- laravel - Laravel webhook 路由返回 405 错误 - 想法?