问题
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