Plink command results not being saved to local text file

瘦欲@ 提交于 2021-02-08 04:56:31

问题


I am calling a remote ssh through PuTTY's Plink functionality - I am able to connect and run my commands but not able to store Output into another text file - my script is as:

plink ssh_hostname -m "directory\till\inputCommand.txt" -l username -pw password > "directory\where\OutputTxt_Will_Be_Saved\OutputRes.txt"

Here OutputRes.txt is created, but it is completely blank. The result is shown on the command line, but not saved into OutputRes.txt (that's what I want to save on).


回答1:


The command probably prints its output to an error output stream, not standard output stream.

To capture the error stream, add 2> redirection:

plink ... 2> "directory\where\OutputTxt_Will_Be_Saved\ErrorRes.txt"

To capture both standard and error outputs to the same file, use 2>&1:

plink ... > "directory\where\OutputTxt_Will_Be_Saved\OutputRes.txt" 2>&1

See Using command redirection operators.



来源:https://stackoverflow.com/questions/45414288/plink-command-results-not-being-saved-to-local-text-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!