Skip to main content
deleted 10 characters in body
Source Link
DavidPostill
  • 158.5k
  • 77
  • 365
  • 408

I am trying to incluideinclude in a batch file - a check to see ofif a java process is already running - before attempting to start it.

I have the following working command;command:

FOR /F "tokens=*" %g IN ('wmic PROCESS where "name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId') DO (SET var=%g)
ECHO %var%

However, the varvar variable is NOT being set correctly.

When I run the initial wmic command I get three lines returned;

 ) Users\gavin>(SET var=ProcessId

 ) Users\gavin>(SET var=4964

 ) Users\gavin>(SET var=

and if I attempt to ECHO %var% I get ECHO is on and not a value.

Can anyone see any tweaks to my command that will allow me to capture the second line?

I am not "stuck on" using wmic... I just care about is this process running, or not.

Thanks!

I am trying to incluide in a batch file - a check to see of a java process is already running - before attempting to start it.

I have the following working command;

FOR /F "tokens=*" %g IN ('wmic PROCESS where "name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId') DO (SET var=%g)
ECHO %var%

However, the var variable is NOT being set correctly.

When I run the initial wmic command I get three lines returned;

 ) Users\gavin>(SET var=ProcessId

 ) Users\gavin>(SET var=4964

 ) Users\gavin>(SET var=

and if I attempt to ECHO %var% I get ECHO is on and not a value.

Can anyone see any tweaks to my command that will allow me to capture the second line?

I am not "stuck on" using wmic... I just care about is this process running, or not.

Thanks!

I am trying to include in a batch file a check to see if a java process is already running before attempting to start it.

I have the following working command:

FOR /F "tokens=*" %g IN ('wmic PROCESS where "name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId') DO (SET var=%g)
ECHO %var%

However, the var variable is NOT being set correctly.

When I run the initial wmic command I get three lines returned;

 ) Users\gavin>(SET var=ProcessId

 ) Users\gavin>(SET var=4964

 ) Users\gavin>(SET var=

and if I attempt to ECHO %var% I get ECHO is on and not a value.

Can anyone see any tweaks to my command that will allow me to capture the second line?

I am not "stuck on" using wmic... I just care about is this process running, or not.

Source Link

Windows 11 DOS FOR/IF

I am trying to incluide in a batch file - a check to see of a java process is already running - before attempting to start it.

I have the following working command;

FOR /F "tokens=*" %g IN ('wmic PROCESS where "name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId') DO (SET var=%g)
ECHO %var%

However, the var variable is NOT being set correctly.

When I run the initial wmic command I get three lines returned;

 ) Users\gavin>(SET var=ProcessId

 ) Users\gavin>(SET var=4964

 ) Users\gavin>(SET var=

and if I attempt to ECHO %var% I get ECHO is on and not a value.

Can anyone see any tweaks to my command that will allow me to capture the second line?

I am not "stuck on" using wmic... I just care about is this process running, or not.

Thanks!