问题
My workflow is to send commands from an emacs buffer to an R session in emacs via the ESS package.
a=0;
system("ssh remotehost ls")
a = a+1;
When I run the three lines above in rapid succession (i.e. submit them to the R buffer), the value of a at the end is 0. When I run them slowly, a is 1.
I've only had this issue running an ssh command via system. In all other cases, the commands queue up and all run sequentially.
My colleagues have the exact same issue with their R/vim setup. But we don't have the same issue in RStudio.
Any suggestions here would be great .
回答1:
ssh
eats up any stdin
during the system()
command. If you paste it line by line then ssh
terminates before you submit a=a+1
and thus it gets passed to R
instead of ssh
. Use system("ssh .. < /dev/null")
or system(..., input="")
if you don't want terminal input to be eaten by the subprocess.
来源:https://stackoverflow.com/questions/28838273/calling-ssh-with-system-in-r-shell-eats-subsequent-commands