|
Post by Johnc on Jun 2, 2018 16:40:12 GMT
How to pass the standard output from RUN VIA CMD /C back to %STRING%?
|
|
|
Post by Johnc on Jun 2, 2018 19:09:35 GMT
perhaps piping to the clipboard may work:
RUN VIA CMD /C | echo something | awk something | clip
The %CLIPBOARD% variable should contain the standard output
Needs some experimentation as I am not sure how the "|" character will be interpreted.
|
|
|
Post by Johnc on Jun 3, 2018 0:53:49 GMT
This is harder than I thought...
on windows 7 command line, this works:
echo hello1 hello2 hello3 | gawk "{print $1}" | clip
(clipboard contains hello1)
but it is not working in MMM:
1 | RUN ACTION | | | | RUN VIA CMD /C | echo hello1 hello2 hello3 | gawk "{print $1}" | clip
nor is:
1 | RUN ACTION | | | | RUN VIA CMD /C | echo hello1 hello2 hello3 \| gawk "{print $1}" \| clip
nor is:
1 | RUN ACTION | | | | RUN VIA CMD /C | echo hello1 hello2 hello3 \| %STRING3% where %STRING3% contains: echo hello1 hello2 hello3 | gawk "{print $1}" | clip
I am not good at escape characters and perhaps there are better ways to pass stdout back to MMM. Thank you in advance for your help Steve!
|
|
|
Post by Johnc on Jun 3, 2018 2:07:33 GMT
I am getting close.
Test Macro as follows:
1 | RUN ACTION | | | | RUN VIA CMD /C | C:\Program_Portable\mmm\script01 2 | RUN ACTION | | | | MESSAGE PROMPT | %CLIPBOARD%::clip
Here I put the following into the batch file script01.bat:
echo hello1 hello2 hello3 | gawk "{print $3}" | clip
It almost worked except I needed to run the macro twice! Not sure why... Any enlightenment? Thanks a lot!
|
|
|
Post by Steve on Jun 3, 2018 3:02:08 GMT
Hi John, Nice one! MMM's handle on managing command IO for stdout or stdin is not great. Saying that though there are some hack work around's to make it work. I think your example looks good. Could be you need to run the script twice because the macro is running too fast and needs a break to process the environmental queues. Check out this example: 1 | RUN ACTION | | | | RUN VIA CMD /C | title=runscript & C:\Program_Portable\mmm\script01 2 | RUN ACTION | | | | WAIT SECONDS | 1 3 | IF | WINDOW TITLE | runscript | NOT EXIST | CONTINUE 4 | RUN ACTION | | | | MESSAGE PROMPT | %CLIPBOARD%::clip
Here we set the cmd window title to 'runscript' and wait 1 second for the cmd to execute. Then at line 3 we check if the WINDOW TITLE for 'runscript' exists. If not we continue. or this one: 1 | RUN ACTION | | | | RUN VIA CMD /C | C:\Program_Portable\mmm\script01 2 | RUN ACTION | | | | WAIT SECONDS | 1 3 | IF NOT | PROCESS NAME | cmd | EXIST | CONTINUE 4 | RUN ACTION | | | | MESSAGE PROMPT | %CLIPBOARD%::clip
Here we check for the process cmd. If NOT process cmd exist then we continue the macro. I'm about to (sometime this month) release an update to MMM that adds some more functionality. It should make IO a bit easier. Until then, mad hacks like this will get it done. Regards, Steve.
|
|
|
Post by Johnc on Jun 3, 2018 3:47:57 GMT
Amazing Steve! The first example worked but I couldn't get the 2nd one to work. This hack should be enough for now and I look forward to your new release. At least I can parse any strings I need now using an external script. Again, I have to say you and MMM are wonderful! Features are so advanced! Thanks again!
|
|