Why cmd process , launched from java, won't start until Java MainFrame application is closed? RRS feed

  • Question

  • I am working on a small app to launch remote commands. I use SwingWorkers to execute cmd commands on remote computers using "schtasks" for scheduling tasks and then activating them so the command is executed by the remote computer.
    Nothing special about the syntax but it goes like:
    For creating a schedule task on remote computer: 

    schtasks /create /s remotePcName /u user /p password /sc once /st 00:00 /tn taskName /tr \\MYPC_NAME\SharedFolder\someBatFile.bat 

    For running it immediately without waiting: 

    schtasks /run /s remotePcName /u user /p password /i /tn taskNameToRunNow 

    Executing the combination of these above two schtasks commands in my cmd creates a single remote command to be executed on remote machine immediately. 

    Now my java app executes a SwingWorker thread for every computer on my remote computerrs list. So each thread is actually executing these two commands on the same runtime and cmd of mine(the computer running the app) but with different parameters.
    On the SwingWorkerThread class it I make two calls to:
    Runtime.getRuntime().exec("cmd /c "+command);
    while the command here as I explained is one of the above schtasks commands.

    The problem is that the commands are being executed only after I close my app. It's like it getting released, and then the schtasks commands(initiated by the SwingWorker Threads) are executed and the remote computers respond to them and execute what they are told to. 

    Why does the schtasks commands get executed only after I close my app?
    Why java has to wait for something before it executes a cmd command from Runtime.getRuntime().exec("cmd /c "+command); ?
    I haven't seen this hapenning to any other cmd command, only on schtasks. But still I don't understand why can't java execute them without having to close my app. 

    please help

    • Moved by Bill_Stewart Friday, January 26, 2018 2:50 PM Off-topic
    Wednesday, November 29, 2017 10:51 AM

All replies

  • We don't support or answer questions about third party apps and tools. Java is an Oracle product. Post in Oracle Java forum for assistance.


    Wednesday, November 29, 2017 11:16 AM