Read window line from parent cmd without writing to file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Izya Kurvitch
Posts: 16
Joined: 15 Jul 2019 15:14

Read window line from parent cmd without writing to file

#1 Post by Izya Kurvitch » 23 Mar 2023 05:16

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 :) .
Last edited by Izya Kurvitch on 24 Mar 2023 06:00, edited 1 time in total.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Read window line from parent cmd

#2 Post by miskox » 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

Izya Kurvitch
Posts: 16
Joined: 15 Jul 2019 15:14

Re: Read window line from parent cmd

#3 Post by Izya Kurvitch » 23 Mar 2023 06:45

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.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Read window line from parent cmd

#4 Post by miskox » 23 Mar 2023 12:27

Run pmon.exe only and post the results (between code tags, please).

Saso

Izya Kurvitch
Posts: 16
Joined: 15 Jul 2019 15:14

Re: Read window line from parent cmd

#5 Post by Izya Kurvitch » 23 Mar 2023 15:34

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...
Last edited by Izya Kurvitch on 24 Mar 2023 06:03, edited 1 time in total.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Read window line from parent cmd

#6 Post by Aacini » 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

Izya Kurvitch
Posts: 16
Joined: 15 Jul 2019 15:14

Re: Read window line from parent cmd

#7 Post by Izya Kurvitch » 24 Mar 2023 05:51

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

Post Reply