0

I am trying to run multiple commands in one line. The codes are below.

WinSCP.com
open user:pw@address
lcd C:\Users\xx\Desktop
get *.xlsx
exit

If I run them one by one, it will work. However, if I want to run them all together using one line, it will fail, no matter I am using ; or &.

For example, if I run WinSCP.com & open user:pw@address, only the first part will be executed.

WinSCP.com; open user:pw@address doesn't work either.

How to execute them using one line?

Thanks

NewGuyComesIn
  • 189
  • 1
  • 2
  • 14

3 Answers3

2

This is happening, because both command line and winscp.com are programs. When you're entering commands one by one you start winscp.com and next entered commands are going directly to the WinSCP. When you're trying to execute all commands at once it is starting WinSCP and waiting for it to finish and then executing next commands.

You definitely can create a text file with your commands and save it as script.txt

open user:pw@address
lcd C:\Users\xx\Desktop
get *.xlsx
exit

And then pass it to the winscp.com application like this:

winscp.com /script=script.txt

It may be possible to send all the commands at once by using /command cmd1 cmd2 ... where cmd1,2 are your commands, but it might be tricky.

References

lks128
  • 936
  • 6
  • 13
0

You can put the sequence of commands in a script file used by WinSCP and call it using the command sequence:

WinSCP.com /script="C:\Users\{name}\Documents\Scripts\{SomeFileName}.scp"

I have found it easier to keep track of what you are doing and keeps the command sequence easier to read.

Wayne_T
  • 1
  • 1
  • Thanks for the answer. But I voted Andrew already. The reason that I put them in one line is I want to put them in VBA so user only needs to press the "button" once to load file. – NewGuyComesIn May 17 '16 at 19:18
0

These are all the possible ways of running multiple commands on a single line :

When you use command1 & command2 on the command prompt, it executes the first command, and then the second command.

command1 && command2 it runs the first command, and then runs the second command only if the first command completed successfully.

command1 || command2 it runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).

(command1 & command2) used to group or nest multiple commands.

Since in your case, you want to run the first command and then do the other operation with-in it; it isn't possible to use any of the above.

You have to write a script which you may call in the same line using a command.

You may do something like this : (WinSCP.com /script=<script_path>) && exit

There are many more options in WinSCP.com command.

Ani Menon
  • 27,209
  • 16
  • 105
  • 126