Get cmd result DIRECTLY!

Discuss and share scripts and script files...
Post Reply
binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Get cmd result DIRECTLY!

Post by binocular222 »

Good news for all: We can run cmd command and receive the result immediately in a variable without piping through a text file.

Recently, SKAN, a founder of Autohotkey made a script to receive cmd result directly http://www.autohotkey.com/board/topic/9 ... douttovar/.
Base on that, I made this exe file:
- Download the .exe
- Run this sample script:

Code: Select all

 run """E:\7Utilities\XYplorer\Data\Scripts\StdOutPlain.exe"" ""ipconfig /all"" ";
 msg get("CopiedData", 3);
SKAN also made another version, which allow receiving result in real time (i.e: we can have a tooltip showing "ping http://www.xyplorer.com" every 1 second). Anyone interest in this realtime version can visit the above link

P.S: With XYplorer's runret command, this script is no longer needed
Attachments
StdOutPlain Unicode x64.zip
(545.78 KiB) Downloaded 298 times
StdOutPlain Unicode x32.zip
(375.76 KiB) Downloaded 248 times
StdOutPlain ANSI x32.zip
(356.19 KiB) Downloaded 247 times
Last edited by binocular222 on 16 Sep 2014 02:18, edited 1 time in total.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

klownboy
Posts: 4141
Joined: 28 Feb 2012 19:27

Re: Get cmd result DIRECTLY!

Post by klownboy »

Hi binocular222,
As a fellow combination XYplorer and AHK user, that script and AHK exe look very promising, but what are the advantages of using it, at least for the example you gave, as oppose to simply using XYplorer by itself? Is it the fact that it eliminates the need have to call out "cmd" via XYplorer?

Code: Select all

run 'cmd /c "C:\Windows\System32\ipconfig.exe /all" > d:\downloads\ipinfo.txt' ,,2,0; open "d:\downloads\ipinfo.txt";  //change folder to suit
Thanks,
Ken
Last edited by klownboy on 13 Sep 2013 15:15, edited 1 time in total.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Get cmd result DIRECTLY!

Post by binocular222 »

The advantage is you don't have to write file to disk, this means:
- No trouble with read-only disks; no worry for "you don't have permission to access this disk location..."
- Other programs may read/write too much on your hard disk at the same time, causing delay in disk writing
- writing to disk is a sloppy work-around, not the way programmers want
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

klownboy
Posts: 4141
Joined: 28 Feb 2012 19:27

Re: Get cmd result DIRECTLY!

Post by klownboy »

Ah yes. Though it this case the writing to disk is relatively minor and quick, it's always better not to if you have a choice. Thanks.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

klownboy
Posts: 4141
Joined: 28 Feb 2012 19:27

Re: Get cmd result DIRECTLY!

Post by klownboy »

You could avoid writing and reading a text file by using the good old "|" pipe command - I'm having flash backs - going back to my DOS batch file days. I also noticed it is discussed in this threadhttp://www.xyplorer.com/xyfc/viewtopic. ... lip#p85097

Code: Select all

run "cmd /C ""C:\Windows\System32\ipconfig.exe /all"" | clip",,2,0; text "<clipboard>", 700, 900, "IP Config";
Another example: you can use this technique when gathering meta data for a photo using Image Magick (file selected in list). Unlike similar examples in other posts, it avoids the disk writes and reads when gathering Image Magick data and at the same time, it's a bit faster.

Code: Select all

run "cmd /C """"D:\Graphics\ImageMagick\identify.exe"" -verbose ""<curitem>"" | clip""",,2,0; text "<clipboard>", 700, 900, "Image Magick Info";
You could use this short script in a CTB menu [change the folder location of Image Magick to suit].
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Get cmd result DIRECTLY!

Post by binocular222 »

Clipboard is modified that way. That's not good at certain times
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

klownboy
Posts: 4141
Joined: 28 Feb 2012 19:27

Re: Get cmd result DIRECTLY!

Post by klownboy »

Hi binocular222, I wasn't in any way trying to knock the use of "StdOutPlain.exe". I think it will be a very handy utility and you know I'm a great fan of AHK as well. I was only coming up with alternatives for those who want to use a method which doesn't rely on a secondary exec or script. It was probably more as a learning experience for me. If you use a clipboard manager, writing to the clipboard really isn't much of an issue. Thanks again.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Post Reply