none
running two commands at the same time from a batch file

    Question

  • Hi all,

    I need some help from you. I am finding it weird actually. When i run command1 & command2 from the command line, both commands run at the same time. But when I am trying to make it run as a batch file, it is not working. I pasted both commands in a notepad and saved it as .bat.

    Anyone knows the reason for that. How can i run two commands at the same time from a batch file?

    any help is appreciated. thanks.

    Friday, February 25, 2011 11:54 AM

Answers

All replies

  • I am not sure we can really help you unless you have the commands posted here.

    The commands might run at the same time only if the first stalls and then CMD executes the second command.

    you might have to add error checks so that the second command doesn't start unless the first one has finished it's action.

     

    you might want to check this site http://www.gameaddict.eu for some cmd scripting.


    Please do not forget to select the best answer if it helps you! The Ultimate computer newbie guide since the discovery of spoon feeding! The Computer Manual dot Com
    Friday, February 25, 2011 2:52 PM
  • command 1: putty -ssh root@192.168.1.200 -pw xxxxx -m c:\test.txt

    command 2: shutdown -s -t 40

    Friday, February 25, 2011 5:25 PM
  • So are you trying to use Putty to connect to a computer and then, shut it down?

     

    Why aren't you just trying to use directly the shutdown command to the remote system.

    shutdown /m \\computer -s -t 40 to shut down the target computer.

     

     

    Im not sure what is that c:\test.txt file supposed to do but you can use the errorlevel output to see if your file exists or not.

    /in the commandbelow I am trying to see if the print spooler is running 

    sc  \\computername query spooler | find /I "STATE" | find /I "stopped"

    /then i verify the answer and continue. with the if else statement.

    if "%ERRORLEVEL%"=="1" (sc \\computername stop spooler) ELSE echo "spooler not running"

     

    you can use the same type of verification.


    Please do not forget to select the best answer if it helps you! The Ultimate computer newbie guide since the discovery of spoon feeding! The Computer Manual dot Com
    Friday, February 25, 2011 6:50 PM
  • let me explain you the situation I am in. I have 1 ubuntu server and 3 xp terminals. All are feeded by an online ups, which can shutdown automatically the terminals when the battery is running low. unfortunately, the driver for the automatic shutdown is not compatible with ubuntu. so what i am thinking of doing is install virtual box on the server and run win xp in it as a virtual machine. so from the xp virtual machine, i ll shut down the server. so basically, i m using putty to connect to the ubuntu server. so from the first command, the -m argument actually refers to the list of commands that i am going to run on the server, which is a shutdown command. then command 2 is to shutdown the win xp virtual machine. so i need both commands to run at the same time. in the 40 seconds i gave in the second command, it should connect to the ubuntu server and send the command. after that, it shut down the virtual machine xp. afterwards, it shut the server. i hope you understood my explanation. i really need your help.
    Sunday, February 27, 2011 6:19 PM
  • you can use the call or start statement to execute another batch file or command without waiting for it to exit.

    http://technet.microsoft.com/en-us/library/bb490873.aspx

    http://technet.microsoft.com/en-us/library/bb491005.aspx

    Depending on what you would like to achieve, it might be needed to split up commands in more than one batch file.


    MCP/MCSA/MCTS/MCITP
    • Proposed as answer by Pavel A Sunday, February 27, 2011 9:32 PM
    • Marked as answer by romeoash Wednesday, March 09, 2011 12:26 PM
    Sunday, February 27, 2011 6:48 PM
  • thank you so much. the command works gr8.
    Wednesday, March 09, 2011 12:24 PM
  • Hi,

    I am using WinPE and have a batch file that i want to run. Inside that file , I am calling/running an HTA application, but it seems rest of the commands after HTA file not executed until I close the HTA application.

    What shoul I do now ? I tried "Call" statement to call the HTA application inside the batch file but still noresults.


    N.A.Malik
    Saturday, September 03, 2011 7:02 PM