Sinisterly
batch files and .exe programs - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: batch files and .exe programs (/Thread-batch-files-and-exe-programs)

Pages: 1 2


RE: batch files and .exe programs - ArkPhaze - 03-30-2013

(03-30-2013, 04:32 AM)Linuxephus Wrote:
(03-30-2013, 03:41 AM)ArkPhaze Wrote: What is to invoke the batch script when you open the program? Understand that this would require functionality from the program that would call the batch script or a hack to the program in question... There's no way to do this in batch.

Yet as you stated, there is a way for a given program to invoke a batch script.
Redshift and Xflux (Google those 2 Linux programs for further referencing) come to mind immediately.
And M[ostly]S[hoddy]'s Windows?
There's a way.
So please, do tell what you're already aware of.

Yes Smile Although for things like Firefox and other programs that aren't really meant to have this functionality, I'm not sure what you would want to do that for... Might as well be better off writing a Firefox addon in some cases, if for instance Firefox was the target.

I wouldn't even hardly write a program myself if all it did was act as a wrapper for invoking a batch script to run via command line through a shell.

I would like to hear why he wants to do this though. There's probably a better alternative here. If he needed it to work this way, it might be better to go through a windows service, that checks the running processes and calls to the batch script based on the conditions it finds for what process you are waiting for.


RE: batch files and .exe programs - ArkPhaze - 03-30-2013

(03-30-2013, 04:32 AM)Linuxephus Wrote:
(03-30-2013, 03:41 AM)ArkPhaze Wrote: What is to invoke the batch script when you open the program? Understand that this would require functionality from the program that would call the batch script or a hack to the program in question... There's no way to do this in batch.

Yet as you stated, there is a way for a given program to invoke a batch script.
Redshift and Xflux (Google those 2 Linux programs for further referencing) come to mind immediately.
And M[ostly]S[hoddy]'s Windows?
There's a way.
So please, do tell what you're already aware of.

Yes Smile Although for things like Firefox and other programs that aren't really meant to have this functionality, I'm not sure what you would want to do that for... Might as well be better off writing a Firefox addon in some cases, if for instance Firefox was the target.

I wouldn't even hardly write a program myself if all it did was act as a wrapper for invoking a batch script to run via command line through a shell.

I would like to hear why he wants to do this though. There's probably a better alternative here. If he needed it to work this way, it might be better to go through a windows service, that checks the running processes and calls to the batch script based on the conditions it finds for what process you are waiting for.


RE: batch files and .exe programs - Linuxephus™ - 03-30-2013

(03-30-2013, 06:46 AM)ArkPhaze Wrote: Yes Smile Although for things like Firefox and other programs that aren't really meant to have this functionality, I'm not sure what you would want to do that for... Might as well be better off writing a Firefox addon in some cases, if for instance Firefox was the target.

I wouldn't even hardly write a program myself if all it did was act as a wrapper for invoking a batch script to run via command line through a shell.

I would like to hear why he wants to do this though. There's probably a better alternative here. If he needed it to work this way, it might be better to go through a windows service, that checks the running processes and calls to the batch script based on the conditions it finds for what process you are waiting for.

I had essentially reached the same conclusion.
However, I wanted further input on the subject from you before commenting with an affirmative.
And yes, a window's service would also have been or would be my own suggestion as it is more of a targeted approach versus a haphazardly needless invocation of a script based upon the executing of a single program to call the scripts function.


RE: batch files and .exe programs - Linuxephus™ - 03-30-2013

(03-30-2013, 06:46 AM)ArkPhaze Wrote: Yes Smile Although for things like Firefox and other programs that aren't really meant to have this functionality, I'm not sure what you would want to do that for... Might as well be better off writing a Firefox addon in some cases, if for instance Firefox was the target.

I wouldn't even hardly write a program myself if all it did was act as a wrapper for invoking a batch script to run via command line through a shell.

I would like to hear why he wants to do this though. There's probably a better alternative here. If he needed it to work this way, it might be better to go through a windows service, that checks the running processes and calls to the batch script based on the conditions it finds for what process you are waiting for.

I had essentially reached the same conclusion.
However, I wanted further input on the subject from you before commenting with an affirmative.
And yes, a window's service would also have been or would be my own suggestion as it is more of a targeted approach versus a haphazardly needless invocation of a script based upon the executing of a single program to call the scripts function.


RE: batch files and .exe programs - noize - 03-30-2013

Well, you could do something like

Code:
:loop tasklist /fi "IMAGENAME eq firefox.exe" 2 > nul | find /i /n "firefox.exe" > nul if "%ERRORLEVEL%"=="0" ( rem - do here whatever you want to do while the browser is running ) goto loop

but it wouldn't start itself when the browser is started, it would just act when the browser runs.


RE: batch files and .exe programs - noize - 03-30-2013

Well, you could do something like

Code:
:loop tasklist /fi "IMAGENAME eq firefox.exe" 2 > nul | find /i /n "firefox.exe" > nul if "%ERRORLEVEL%"=="0" ( rem - do here whatever you want to do while the browser is running ) goto loop

but it wouldn't start itself when the browser is started, it would just act when the browser runs.


RE: batch files and .exe programs - ArkPhaze - 03-30-2013

(03-30-2013, 07:25 PM)noize Wrote: Well, you could do something like

Code:
:loop tasklist /fi "IMAGENAME eq firefox.exe" 2 > nul | find /i /n "firefox.exe" > nul if "%ERRORLEVEL%"=="0" ( rem - do here whatever you want to do while the browser is running ) goto loop

but it wouldn't start itself when the browser is started, it would just act when the browser runs.

as long as you endlessly run this script... That script looks like it has errors in it though. I would do this:
Code:
@echo off & setlocal enabledelayedexpansion :loop set lookfor=firefox.exe for /f "tokens=1" %%G in ('tasklist /FI "ImageName eq %lookfor%" /NH') do set found=%%G if /i %found%==%lookfor% ( echo %lookfor% is running... ) goto loop



RE: batch files and .exe programs - ArkPhaze - 03-30-2013

(03-30-2013, 07:25 PM)noize Wrote: Well, you could do something like

Code:
:loop tasklist /fi "IMAGENAME eq firefox.exe" 2 > nul | find /i /n "firefox.exe" > nul if "%ERRORLEVEL%"=="0" ( rem - do here whatever you want to do while the browser is running ) goto loop

but it wouldn't start itself when the browser is started, it would just act when the browser runs.

as long as you endlessly run this script... That script looks like it has errors in it though. I would do this:
Code:
@echo off & setlocal enabledelayedexpansion :loop set lookfor=firefox.exe for /f "tokens=1" %%G in ('tasklist /FI "ImageName eq %lookfor%" /NH') do set found=%%G if /i %found%==%lookfor% ( echo %lookfor% is running... ) goto loop