I am trying to control a remote Python script, which reads commands from stdin, via psexec 1.98, but I need to redirect psexec's input since psexec itself will be launched from another program. However, I have no luck making psexec accept redirected input. Is it supposed to work at all?

An example of what I'm trying to do, where input is a file containing input to the remote script:

psexec \\mymachine python c:\script.py < input
  • Are you trying to read a file on your computer, or on the remote computer? – cstamas Apr 10 '11 at 21:05
  • @cstamas: the input file would be local, since psexec's stdin should be redirected to it. – aknuds1 Apr 11 '11 at 17:34
  • I doubt the answer is yes. PSEXEC has to send the commands you instruct it to run to the remote computer before they are executed (otherwise the command would be incomplete and fail). So that makes me think it does so one time and there's no further interaction with the source computer such that input from later in the command pipeline isn't possible. – I say Reinstate Monica Jan 31 '15 at 22:28
  • @Twisty You are wrong, since you can run psexec \\someserver -u "user" -p "password" -acceptEula cmd, and provide any further commands you wish. – Asad Saeeduddin Jun 6 '16 at 18:09

The issue is that it thinks that "...script.py" is the end of your command. If you put quotes around it

psexec \\mymachine python "c:\script.py < input"

Then you should be fine.

Additionally, you'll probably need to specify an absolute path to that input file.

Two examples:

psexec \\mymachine python "c:\script.py < \\input_file_server\input"
psexec \\mymachine python "c:\script.py < c:\input"

That should do it for you.

  • I don't think this method works? Putting the < operator inside quotes like this makes it part of the argument to Python. I tried it just to check, and in your second example Python thinks it's supposed to open the file "c:\script.py < c:\input". – aknuds1 Jan 17 '11 at 16:19
  • Also, are you thinking that I am trying to redirect the input to the Python command? That's not what I am trying to do. I am trying to redirect the input to psexec. – aknuds1 Jan 17 '11 at 16:22

What about these:

psexec \\mymachine cmd /c "python "c:\script.py < input"


psexec \\mymachine cmd /k "python "c:\script.py < input"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.