i have 3 commands to run in Windows terminal, but all of them should start in parallel roughly at the same time. I created .bat file, put my 3 commands in there and had run that bat file. But the commands are being executed in serial fashion(second command executes only after first one is finished). Is there a special way to do this in Windows?
What if i have to run the same command/exe i parallel, but with different arguments? I mean, lets suppose i have two commands, iperf.exe -s -u -i 1 10.10.100.1 and iperf.exe -s -u -i 1 10.10.100.2; Will these execute in parallel if i enter below lines in .bat file and run it?
start iperf.exe -s -u -i 1 10.10.100.1
start iperf.exe -s -u -i 1 10.10.100.2
And, even if they run in parallel, will there be any interruptions(even the slightest) while executing parallel processes like if one thread is dependent on another or will they execute strictly parallel like each command is an independent process? Because i need the programs to run at the same time and they should behave like separate and independent processes without any dependency or interruptions. Will START provide me with such kind of functionality?
In batch, use the start command, followed by the command you want to launch. All arg:
start iperf.exe -s -u -i 1 10.10.100.1
start iperf.exe -s -u -i 1 10.10.100.2
In PowerShell, use Start-Process (you can also call it "start", that's a built-in alias for Start-Process:
Start-Process iperf.exe -ArgumentList '-s -u -i 1 10.10.100.1'
Start-Process iperf.exe -ArgumentList '-s -u -i 1 10.10.100.2'
[Note: My answer appears to repeat information from the question because the question was edited to include information from my answer. The original question didn't mention the start command, it just asked how to start processes in parallel using batch or PowerShell.]
To answer the revised question: Both cmd's start and PowerShell's Start-Process spwan a child process, not a thread in the original process. In Windows, child processes are entirely independent from each other and from the parent. I've used both of these many, many times to launch applications that run separately, and can assure you that their operation is no more interdependent than if you had launched them in any other way.
The equivalent of start in PowerShell is Start-Process as has been pointed out but getting the parameters to the exe is a bit tricky e.g.:
Start-Process iperf -arg -s,-u,-i,1,10.10.100.1
Start-Process iperf -arg -s,-u,-i,1,10.10.100.2
I assume the exe runs until you press Ctrl+C or press enter? Otherwise the window opens, runs and then exits.
I think you just can't, neither in batch, nor in OS.
To minimize OS process loading overhead, you may try via Windows API to load all process suspended (CreateProcess, CREATE_SUSPENDED) and then, in a fast cycle start all threads (ResumeThread).
But I can't see any way to do that with command line, you have to go through programming.
Sorry to post it as a Reply, but not enough reputation to comment.
Insteady of:
Start-Process iperf -arg -s,-u,-i,1,10.10.100.1
Start-Process iperf -arg -s,-u,-i,1,10.10.100.2
You can do:
$params='-s -u -i 1 '
$ips=#('10.10.100.1','10.10.100.2')#and other more ips
$ips | foreach-Object{ Start-Process iperf -ArgumentList "$($params)$($_)"}
Then you can get the IP's from a list file, escalate and more.
I was looking for something like this when I've find your question.
Related
I have this batch script:
C:\{Directory}\PsExec.exe -u {UserName} -p {Password} \\{IP_Address} /accepteula "C:\batchfiles\{BatchScript}.bat"
And the {BatchScript}.bat script is:
C:\{Directory}\infacmd.bat wfs startWorkflow -DomainName {Domain_Name} -ServiceName {Service_Name} -UserName {Username} -Password {Password} -Application {Application} -Workflow {Workflow} -wait
This script kicks off an Informatica process to build a data warehouse (not sure if that's important, but thought I would mention it). When I run the first batch script, it kicks off the second batch script. However, it seems like command prompt waits for Informatica to be finished before it exits. My issue is that I have other processes that need to run, and this process takes 5 hours currently. Is there a command I can add on to my second (or first) script that will exit command prompt immediately after it kicks off? I don't believe this will impact the data warehouse build since I don't need Windows to monitor the process.
start "windowtitle" C:\...whatever...\infacmd.bat w....
should do what you want...
We are in the need of spawning processes from session 0 isolation to a logged in user in session 1.
This task is done by using psexec, this happens entirely on the same machine, but I am unable to get the output of the child process to be displayed in psexec. Since this runs on a build-server I don't want to redirect output to a file, etc
Here is a sample call which does not work:
C:\>PsExec.exe cmd.exe -i 1 -u user -p pwd /C echo foo
The result shows nowhere any "foo"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd.exe exited with error code 0.
One thing that works, but is currently useless is to ommit -i and add \\localhost:
C:\>PsExec.exe \\localhost cmd.exe /C echo foo
returns:
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
foo
cmd.exe exited on localhost with error code 0.
But when I specify session 1, it breaks. This:
C:\>PsExec.exe cmd.exe -i 1 -u user -p pwd \\localhost /C echo foo
again shows no foo for me.
Again: The intention is not to tee or redirect echo foo into some file and then perform type myfile.log as a second step but to receive the output in the original psexec.
We are bound to session 1 as we need a Direct 3D context, having the service configured with "Allow interacting with the desktop" does not help here.
I don't think that what you are asking is possible. psexec -i runs the process interactively on the remote machine, so everything including the console I/O happens in the respective session on the remote machine.
The -i behavior does in fact make sense. Suppose for example that you ran a batch file which required user input e.g. had a pause or set /p. With -i that input would need to be entered on the target machine, not on the machine where you run psexec. Similarly, the output goes (only) to the remote machine.
The other part of your question is the difference between psexec \\localhost and psexec without a computer name at all. This one appears to be an undocumented psexec quirk, which has been noticed and reported before, for example (with a bit of reading between the lines) at Redirect output of process started locally with PSExec.
I have written a batch file like this:
Start putty.exe -ssh 172.17.0.52 -l root -m dummy.txt
Then in dummy.text I have written this command:
avahi-daemon --no-drop-root -D
export XVHMI_USERCONFIG_PATH=/home/UserProfileConfig
export XDG_RUNTIME_DIR=/tmp
cd /opt/bosch/airis/bin
When I run the .bat file, PuTTY starts, commands execute (hopefully, not sure) and it exits.
How to keep that window open?
I have googled for the same, but no solid help. I read on stack overflow itself that we need to define something in txt file, but what and most importantly how?
The SSH session closes (and PuTTY with it) as soon as the command finishes. Normally the "command" is shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:
avahi-daemon ... ; /bin/bash
Also as use of -m switch implies a non-interactive terminal, you probably want to force an interactive terminal back using -t switch.
Though, I'm not really sure if you want to execute shell or if you just want to see your command output. If the latter, did you consider using plink? It's console terminal client from PuTTY package. Being console application, it inherits console of parent batch file, and you can pause the batch console from closing using pause command, if needed.
Another option (both for PuTTY and plink) is to pause on remote side. E.g. Using read command.
avahi-daemon ... ; read
As suggested by Martin I tried this step:
putty.exe -ssh 172.17.0.52 -l root -m dummy.txt -t
added /bin/bash at the end of commands in dummy.txt
It worked for me. Please note, you have to follow both the steps as mentioned above.
This way you can keep the session alive and can manually execute further commands.
I would like to run n processes (in my case simulations) simultaneously, using bash.
Right now this is what I'm running:
for file in $ini/SAN*.ini;
do
echo "Running $file...";
temp=$(basename $file .ini)
mosrun -G opp_run -r 0 -u Cmdenv -n ..:../../src -l ../../src/inet SAN.ini > $outputs/$temp.out;
done
Problem is, the loop only progresses to the next iteration after the simulation is done. Any suggestions? Thanks!
You should be able to run your command in the background by adding a & after it.
Should make them run in parallell, although in the background.
(Small side note: the processes will continue to run even if you abort the script, so you might want to add a trap to kill the processes if you hit for eg. ctrl-c when script is running. Look at bash manual.)
I need to start some process on winXP with "start" command.
Sounds simple.
But is there a way that the started process would not inherit any ports from parent?
I start children in my program using:
system "start x -params"
Now when parent is being killed, I can't start it again because I'm learned by errors that some process is already occupying port (which killed parent was using).
I don't want to use:
createProcess (from winAPI, where this can be setup to not inherit fds)
use python in my start string (or any similar interpreters)
Is there a way to start my child process in a way I want them to start?
Is there any "start" alternative?
So after diggin a while, i've found:
psexec
with commandline like:
psexec -d -s myprogram > logfile.log 2>&1
everything is solved.
powershell -command "Start-Process myprogram.exe"