vee*_*ain 0 io perl command-line cmd io-redirection
我遇到的问题与我在这里看到的很多帖子相反。
我正在运行其他人编写的 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.
Run Code Online (Sandbox Code Playgroud)
Windows 是否有一些奇怪的东西可以创建/阻止 > 运算符行为?
关键是:我做得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
Run Code Online (Sandbox Code Playgroud)
请注意,2>&1如果您想合并两个流,则必须在重定向 STDOUT 之后进行。