-1

I am trying to execute a batch file (.bat) with the following commands in the batch file. I have a batch file containing the following;

@ECHO OFF
cmd.exe /K "cd C:\Program Files (x86)\PuTTY && C:"
set PATH=%PATH%;C:\Program Files (x86)\PuTTY
pause
plink.exe -ssh username@firewall1 -pw PassWord! < commands.txt > c:\output_.csv"
pause

the plink.exe command works when entered in manually.

commands.txt is just a simple firewall command for now.

All I see when running the batch file is a cmd window open point at the Putty folder, and that's it.

So how can i get this to run please?

RJGA
  • 17
  • 1
  • 7
  • What does the command **`C:`** mean? Also the recommended way to `Set` a variable is `Set "VariableName=VariableValue"`; _the double quotes being important_. – Compo Jan 09 '18 at 12:19

2 Answers2

0

Your batch file at line 2, opens a new cmd window. That's not probably what you want. Also it changes the current directory and the current drive, read HELP CD, and then change that line to just cd /d "C:\Program Files (x86)\PuTTY"

Also, as a bonus recommendation, you are changing the PATH every time you run this command, adding the putty directory that you mage as current anyway, so this command is unnecessary and redundant.

So, I would leave your bat as simple as

@ECHO OFF
CD /D "C:\Program Files (x86)\PuTTY"
plink.exe -ssh username@firewall1 -pw PassWord! <commands.txt >c:\output_.csv
PA.
  • 28,486
  • 9
  • 71
  • 95
  • Actually one other issue, when i'm running plink it shows the cmd prompt box with username, how do i remove this command prompt box, it never exits after i've ran the .bat file. – RJGA Jan 09 '18 at 14:23
0

I would suggest making the batch file simpler still:

@Start "" /D "%ProgramFiles(x86)%\PuTTY" plink.exe -ssh username@firewall1 -pw PassWord! <commands.txt >C:\output_.csv

You may consider running other options such as /MIN, type Start /? at the command prompt for usage information

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Maybe to advance for me, I'm not sure what to put in the ""? As I just ran your script in .bat file and nothing happened. I have another question on my board which is hindering my process. – RJGA Jan 09 '18 at 15:10
  • You can add a window title between them if you want otherwise keep the doublequotes empty, they should remain there. – Compo Jan 09 '18 at 15:17