Page 1 of 1

Read window line from parent cmd without writing to file

Posted: 23 Mar 2023 05:16
by Izya Kurvitch
Sholom there!
Trying to write 2nd's cmd window's stdout that starts from 1st cmd to a variable but haven't succeed yet... Seems to me that some redirection with "1", "2", "&" must take place, but don't know how to do it... Here's my trying:


for /f "usebackq tokens=2 delims=: " %i in (`start /i pmon.exe ^|findstr /i "memory"`) do echo %i

Here the 2nd processing cmd line of the pmon.exe proccess:
Memory: 2000000K Avail: 500000K PageFlts: 15000 InRam Kernel:10000K P:200000K

The result must be "2000000K" in 1st window, 2nd window must be closed. Thanks :) .

Re: Read window line from parent cmd

Posted: 23 Mar 2023 06:24
by miskox
What happens if you remove the 'start' command?

Code: Select all

for /f "usebackq tokens=2 delims=: " %i in (`pmon.exe ^|findstr /i "memory"`) do echo %i
Saso

Re: Read window line from parent cmd

Posted: 23 Mar 2023 06:45
by Izya Kurvitch
miskox wrote:
23 Mar 2023 06:24
What happens if you remove the 'start' command?

Code: Select all

for /f "usebackq tokens=2 delims=: " %i in (`pmon.exe ^|findstr /i "memory"`) do echo %i
Saso

Nothing. The cursor hangs in the parental window, and the pmon.exe window does not start ... It could be another cmd utility, not necessary pmon.exe. The idea is to read line in secondary window and output it to parental one.

Re: Read window line from parent cmd

Posted: 23 Mar 2023 12:27
by miskox
Run pmon.exe only and post the results (between code tags, please).

Saso

Re: Read window line from parent cmd

Posted: 23 Mar 2023 15:34
by Izya Kurvitch
miskox wrote:
23 Mar 2023 12:27
Run pmon.exe only and post the results (between code tags, please).

Saso
Here the first line of the pstat.exe window... others are similar:

Code: Select all

Pstat version 0.2:  memory: 2000000 kb  uptime:  1 5:49:06.598 
I have positive result with writing to file and then proccessing the line (mistake in 3rd line is corrected below):

Code: Select all

@echo off
pstat.exe>c:\1.txt
for /f "usebackq tokens=5 delims=: " %%i in ('findstr "memory" "c:\1.txt"') do @echo %%i

2000000
dbenham wrote:
It sounds like you are trying to communicate between different processes, which would require communication via files. I use that technique in my SNAKE.BAT batch game. Buried in that thread is a description of how the inter-process communication works.
I trust him, as he's an expert, but still seeking a way to do it without writing to file using operative memory only...

Re: Read window line from parent cmd

Posted: 23 Mar 2023 19:51
by Aacini
Accordingly to your last test, this should work:

Code: Select all

for /f "usebackq tokens=5 delims=: " %%i in ('pstat.exe ^| findstr /i "memory"') do echo %%i
Note that you changed the "backtit" ("`" character) by apostrophe...

If this not works, remove the usebackq option from FOR /F switch.

Antonio

Re: Read window line from parent cmd

Posted: 24 Mar 2023 05:51
by Izya Kurvitch
Aacini wrote:
23 Mar 2023 19:51
Accordingly to your last test, this should work:

Code: Select all

for /f "usebackq tokens=5 delims=: " %%i in ('pstat.exe ^| findstr /i "memory"') do echo %%i
Note that you changed the "backtit" ("`" character) by apostrophe...

If this not works, remove the usebackq option from FOR /F switch.

Antonio
Of course, it's my inattention... Tnaks for your notice.

Code: Select all

@echo off
pstat.exe>c:\1.txt
for /f "tokens=5 delims=: " %%i in ('findstr "memory" "c:\1.txt"') do @echo %%i

2000000