danel94
danel94

Reputation: 11

PuTTY -m command option failing with "unable to open ... file" on Windows 7

I'm trying to make an automatic PuTTY login using a batch file. I have this:

start "title" "C:\Program Files\PuTTY\putty.exe" "server_name@server_IP" -pw "password" -m "commands_to_execute.txt"

Everything works on my Windows 10 machine but in Windows 7, the command option -m does not work. The error message is:

unable to open command file:"commands_to_execute.txt"

I have tried changing all paths to "C:\Program Files\PuTTY", setting the working directory /D, working in the actual directory and I also add the path to the enviroment variables in:

Advance system settings >Enviroment Variables

I have also used plink instead of putty.

What is happening?

Upvotes: 1

Views: 11039

Answers (2)

Legion49f
Legion49f

Reputation: 1

you need to use plink.exe for this not putty.exe, just replace:

start "title" "C:\Program Files\PuTTY\plink.exe" "server_name@server_IP" -pw "password" -m "commands_to_execute.txt"

or make it even easier:

cd C:\Program Files\PuTTY\
plink.exe -ssh pi@192.168.1.166 -P 22 -pw P@SSWRD ~/script.sh
plink.exe -ssh pi@192.168.1.166 -P 22 -pw P@SSWRD -m commands.txt 
pause

either of the two lines work.

Upvotes: 0

Martin Prikryl
Martin Prikryl

Reputation: 202642

It is very unlikely that your problem has anything to do with Windows 7 vs Windows 10.

Most likely the working directory for your batch file execution on Windows 7 is not set to the folder, where the commands_to_execute.txt file is stored.

Possible solutions are:

  • Set the working directory the same way you have set it on Windows 10

  • Use a full path to the script file:

    -m "C:\path\to\commands_to_execute.txt"
    
  • Set working directory for PuTTY explicitly using:

    start "title" /D "C:\path\to" "C:\Program Files\PuTTY\putty.exe"  ...
    
  • Or, if the script file is in the same folder as your batch file, you can use:

    start "title" /D "%~dp0" "C:\Program Files\PuTTY\putty.exe"  ...
    

Upvotes: 2

Related Questions