0

I need to connect remotely in another network with putty and then start a windows remote desktop connection. these are 2 steps with 2 sets of passwords, I want to just have one batch script to run once for both steps.

I did the single commands:

pathPuttyexe -load "myconnection" -pw password

to connect from windows 10 with putty, then

mstsc myfileconfig.rdp 

to run the remote desktop connection application with my configuration.

The problem I have is if I put the 2 commands in one bat file, it executes the second only after the first is finished. That means while the connection to the other network is live, the Remote Desktop Connection app doesn't run. The & didn't work; with while do I couldn't make it work...

Compo
  • 36,585
  • 5
  • 27
  • 39
Petronella
  • 2,327
  • 1
  • 15
  • 24
  • 1
    Use `|` Here is an example: `pathPuttyexe -load "myconnection" -pw password | mstsc myfileconfig.rdp` or use `start` – Gerhard Nov 03 '20 at 14:45
  • `|` mean "or", I want both not one. Where to use 'start'? – Petronella Nov 03 '20 at 14:52
  • yes, so if they are on the same line use `|` but if you want normal batch file, you start each one. So `start "" mstsc myfileconfig.rdp` then the next line you do the same for putty. – Gerhard Nov 03 '20 at 14:59
  • The [`&`](https://ss64.com/nt/syntax-redirection.html) operator executes one command after the other. The [`|`](https://ss64.com/nt/syntax-redirection.html) is called a *pipe* and is used to pass the output of one command into the input of another one; since this happens asynchronously, meaning that both commands are run concurrently and do not wait on each other, you can misuse a pipe for your purpose, although this does not work in general. So using `start` is the approach I recommend… – aschipfl Nov 03 '20 at 21:48

1 Answers1

0

To start them in sync as a one liner:

pathPuttyexe -load "myconnection" -pw password | mstsc myfileconfig.rdp

Or using start:

start "" mstsc myfileconfig.rdp
start "" pathPuttyexe -load "myconnection" -pw password

If you want to run it in sequence, in other words the one starts after the other and on at the same time:

pathPuttyexe -load "myconnection" -pw password & mstsc myfileconfig.rdp

or with conditional operator && meaning the second process will only start IF the first started successful.

pathPuttyexe -load "myconnection" -pw password && mstsc myfileconfig.rdp

or just straight forward line seperated:

mstsc myfileconfig.rdp
pathPuttyexe -load "myconnection" -pw password
Gerhard
  • 22,678
  • 7
  • 27
  • 43