-1

I am trying to run a on remote machine, from through commands.

sshpass -p 'password' ssh username@server < abc.bat

I want to send argument to my batch file.

sshpass -p 'password' ssh username@server < abc.bat variable1

I get error

'variable1' is not recognized as an internal or external command, operable program or batch file

In my batch file I want to read this variable1 and pass it to one exe that I use as parameter.

set var1=%1
xyz.exe %var1%

Can someone help.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    In your batch file you do not need to define a variable, just use `xyz.exe %1`. In future, please format the content of your questions, or answers, using the code and blockquote buttons as needed. – Compo Sep 25 '20 at 10:16
  • Thanks for the suggestion Compo. i tried accessing the variable directly as well, but I am getting the error while i call the batch file with argument. Somehow argument is not getting recognised – ravi kumar Sep 25 '20 at 10:24
  • Well, this does not execute `abc.bat`, it sends the text contents of `abc.bat` to `sshpass` via the _STDIN_ handle. Please [edit] the qurestion and exactly explain what you want… – aschipfl Sep 25 '20 at 12:01

1 Answers1

0
ssh username@server "abc.bat variable1"

That command will run abc.bat and provide variable1 as the first argument.

However, be wary of chaining commands like sshpass. In the following example,

sshpass -p 'password' ssh username@server "abc.bat variable1"

will "abc.bat variable1" be an argument of ssh or sshpass?? I do not know, I do not use sshpass, but it is a confusion that can occur.

jnovack
  • 7,629
  • 2
  • 26
  • 40