1

I need to run this command

LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script

Next line in batch should be processed after this is finished. Now, there's many ways, bt I'd prefer something as easy as START /WAIT, but no matter how hard I try, running this with START results in The system cannot find the file specified.


After demon.devin's answer this is the solution:

:CHECK_RUNNING

    set errorlevel=
    tasklist /fi "imagename eq noppack.exe" | find /i "noppack.exe"> NUL
    if /i %errorlevel% GTR 0 goto CONTINUE
    ping -n 1 -w 5000 1.1.1.1 > nul
    goto CHECK_RUNNING

:CONTINUE
[...]
  • don't know nothing about `LEProc.exe`, but `runas` will spawn a new cmd session starting at `%SYSTEMROOT%\System32`. So my initial guess is not to rely on `%~dp0`. Fully qualify all paths of exe and data files. – elzooilogico Aug 29 '17 at 08:52
  • `LEProc` is just Locale Emulator, needed to run `noppak.exe` in Korean locale. It is not for delaying... – George Hovhannisian Aug 29 '17 at 08:56
  • I insist in full qualify paths `start "" /wait cmd /c ^""c:\some_folder\LEProc.exe" -runas ba954abf-...-4b6d90aed470 "c:\your_folder\another_folder\noppack.exe" "c:\your_folder\whatever\data script"^"` – elzooilogico Aug 29 '17 at 10:18
  • also, `start "" /D "c:\some_folder" /wait cmd /c ^"LEProc.exe -runas ba954abf-...-4b6d90aed470 "%~dp0Release\noppack.exe" "data script"^"`. Quoting `start` is tricky. – elzooilogico Aug 29 '17 at 10:24
  • @elzooilogico OK, I don't understand what `"^"` is, should I change it somehow or do I just copy it to my batch (I can't figure out the syntax for `START` for something like this). Also, `LEProc.exe` is in my path. – George Hovhannisian Aug 29 '17 at 10:32
  • @elzooilogico That still results in `The system cannot find the file specified.`. – George Hovhannisian Aug 29 '17 at 10:39
  • you should begin reading the `start /?` help screen. Quoting `start` along with `cmd` is tricky. `^"` is just escaping the quotes `cmd` needs when spawned from `start`. you may test several combinations. Another workaround may be creating a batch script with the whole command and run `start "" /D "c:\your_folder" /wait cmd /c "script_name.bat"` – elzooilogico Aug 29 '17 at 10:45
  • the message `The system cannot find the file specified.` tells you that the command proccesor can't find the correct path. What happens it you run `LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 cd` – elzooilogico Aug 29 '17 at 10:47
  • @elzooilogico OK. I'm gonna try that. Make new batch file and call it from the main batch. – George Hovhannisian Aug 29 '17 at 10:48
  • The problem is `START /WAIT` waits for `LEProc.exe` and that exits as soon as it executes the program in correct locale. Is there a way to tell the batch script to wait for `noppack.exe`, even though it's not running it directly? – George Hovhannisian Aug 29 '17 at 11:10
  • does this work? `LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "START /D "c:\your_folder" /WAIT "%~dp0Release\noppack.exe" "data script"" ` – elzooilogico Aug 29 '17 at 11:20
  • No, that doesn't do anything at all – George Hovhannisian Aug 29 '17 at 11:23
  • Sorry, as I've said before cannot test `LEProc.exe` so I cant get any further. Does it run `cmd` and all related commands ok? Then this should do the job `LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "START /D "c:\your_folder" /WAIT ^"cmd /c "%~dp0Release\noppack.exe" "data script"^""` – elzooilogico Aug 29 '17 at 11:27
  • 1
    In refererence to @LotPings answer, take a look at this https://stackoverflow.com/a/8185270/2441. – aphoria Aug 29 '17 at 12:01

2 Answers2

2

It looks like LEproc.exe spawns another process.
Then it returns and there is no use waiting for LEproc.exe while you want to know when Noppack.exe is finished.

You should check with tasklist/pslist and a loop (with a delay) if nopppack.exe is still running.

  • Where do I get those? – George Hovhannisian Aug 29 '17 at 12:38
  • @GeorgeHovhannisian [tasklist](https://ss64.com/nt/tasklist.html) is part of windows. – Stephan Aug 29 '17 at 12:50
  • 1
    tasklilst is part of windows, [pslist](https://learn.microsoft.com/en-us/sysinternals/downloads/pslist) See the link in [aphoria's comment](https://stackoverflow.com/questions/45934393/batch-file-wait-for-program-with-complex-command-line-finish/45938425?noredirect=1#comment78835018_45934393) –  Aug 29 '17 at 12:53
1

I haven't tested this but maybe this can help..

@echo off
goto begin

:: INFO: Check to see if a process is running and if so wait before launching
::       a new process. After checking for a process this .bat file will wait 
::       for a set amount of seconds declared be the user before checking and
::       looping again or moving onto the next command.

:: EDIT: Change "seconds=" to "seconds=15000" to set a time of 15 seconds for
::       the wait period. For 5 seconds change it to "seconds=5000" For extra
::       commands you should add "set app3=AnotherProcess.exe" and repeat for
::       more if need be but be sure to compensate for the new command below.

:begin

:: Set length in seconds here
set seconds=

:: Set your processes here
set app1=noppack.exe
set app2=NewProcess.exe

:: Do not edit


:: First loop check
echo.
echo.
echo Starting the LEProc.exe process...

LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script

:check_one
    cls

    set errorlevel=

    tasklist /fi "imagename eq %app1%" | find /i "%app1%"> NUL

    if /i %errorlevel% GTR 0 goto complete_one

    echo.
    echo The %app1% process is running!
    echo.
    echo Will check again in a few seconds.
    echo.
    ping -n 1 -w %seconds% 1.1.1.1 > nul
    goto check_one

:: First process complete
:complete_one
    echo.
    echo The %app1% process has finished!
    echo.
    echo Starting the %app2% process...

    START /WAIT %app2%

:: Second loop check
:check_two
    cls

    set errorlevel=

    tasklist /fi "imagename eq %app2%" | find /i "%app2%"> NUL

    if /i %errorlevel% GTR 0 goto complete_two

    echo.
    echo The %app2% process is running!
    echo.
    echo Will check again in a few seconds.
    echo.
    ping -n 1 -w %seconds% 1.1.1.1 > nul
    goto check_two

:: Second process complete
:complete_two
    echo.
    echo The %app2% process has finished!

pause

Read the commented section for usage and what to edit.

If @LotPings isn't correct then change app1=noppack.exe to app1=LEProc.exe.

Hope this helps!

=)

daemon.devin
  • 128
  • 1
  • 5
  • Yes! This is what I needed. I had to heavily truncate it, though; I don't need the second app part. You see the next few lines in my batch file don't run a new app, they actually remove the the 2 folders `NOPPack` has (supposedly) already packed (`data` and `script`) and renames the resulting NOP file into a releasable name. Obviously, I don't want to do either of those, until `Noppack` has finished doing its thing. See the OP for the lines I actually ended up using. – George Hovhannisian Aug 30 '17 at 09:41