How to assign stdout to variable?

Discuss and share scripts and script files...
admin
Site Admin
Posts: 66258
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to assign stdout to variable?

Post by admin »

Okay, don't tell anybody, but I got hooked and tried something (next beta): a new function runret which will run a command line and return the stdout. It *seems* to work -- I really have no time for debugging this... :P

Example:

Code: Select all

text runret("ping localhost");

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: How to assign stdout to variable?

Post by Huidong »

Holy moly, can't wait!

Thank you, Don!

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How to assign stdout to variable?

Post by bdeshi »

Wheeeeeeeeeeeeeeeeeeeeeeeee! :biggrin: :biggrin: :biggrin:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How to assign stdout to variable?

Post by bdeshi »

When you're debugging:
There seems to be some problems with line width:
cmd prompt output (!dir) :

Code: Select all

 Volume in drive C has no label.
 Volume Serial Number is E6DD-0CF9

 Directory of C:\Portable\XYplorer\XYData\Scripts\WIP\demo

06/03/2014  11:48 PM    <DIR>          .
06/03/2014  11:48 PM    <DIR>          ..
06/03/2014  11:48 PM                 0 some.xys
06/03/2014  11:48 PM                 0 somefile.txt
               2 File(s)              0 bytes
               2 Dir(s)  31,398,719,488 bytes free

C:\Portable\XYplorer\XYData\Scripts\WIP\demo>
[/size]
versus output of XY text runret("cmd /c dir"):

Code: Select all

 Volume in drive C has no label.

 Volume Serial Number is E6DD-0CF9

 Directory of C:\Portable\XYplorer\XYData\Scripts\WIP\demo

06/03/2014  11:48 PM    <DIR>          .
06/03/2014  11:48 PM    <DIR>          ..
06/03/2014  11:48 PM                 0 some.xys
06/03/2014  11:48 PM  
               0 somefile.txt
               2 File(s)              0 bytes
               2 Dir(s)  31,398,719,488 bytes free

C:\Portable\XYplorer\XYData\Scripts\WIP\demo>
[/size]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: How to assign stdout to variable?

Post by Marco »

Confirmed. Plus, can something be done for mismatching codepages/encoding?

!dir

Code: Select all

 Il volume nell'unità C non ha etichetta.
 Numero di serie del volume: xxxx-xxxx

 Directory di C:\x

03/06/2014  18:42    <DIR>          .
03/06/2014  18:42    <DIR>          ..
               0 File              0 byte
               2 Directory  92.942.864.384 byte disponibili
text runret("cmd /c dir");

Code: Select all

 Il volume nell'unit… C non ha etichetta.

 Numero di serie del volume: xxxx-xxxx

 Directory di C:\x

03/06/2014  18:42    <DIR>          .
03/06/2014  18:42    <DIR>          ..
               0 File              0 byte
               2 Directory  92.942.868.480 byte dispo
nibili
PS: this is the Holy Grail of scripting ;)
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 66258
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to assign stdout to variable?

Post by admin »

Okay, next beta will see some improvements here. Damn, I'm spending too much time on this... :whistle: :biggrin:

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How to assign stdout to variable?

Post by klownboy »

Huidong (or anyone else) have you tried running the "runret" with MediaInfo (or another CLI program) in a Custom Column yet? Though cmd /c can be used, I found this command as follows works without the need of the "cmd /c" before it.

Code: Select all

 $a = runret("D:\DVD\MediaInfo\MediaInfo.exe --output=Video;%Height%x%Width% ""<cc_item>""");   //or you can use ...("cmd /c D:\DVD\...
 return substr($a, 0, -2);
However and it's a big however, the new command (and I realize that Don is obviously still working out the kinks) you'll get a command box flashing for each file entry it's obtaining the data (whether cmd /c is used or not).

The problem is, especially important for use in Custom Columns. We'll need a "show" parameter with "runret" which hides (noshow) the command box as we have for the run command. We may also need a wait parameter in some cases.

Don, you said, you're spending too much time on this, but heck it is a great feature. :appl:

admin
Site Admin
Posts: 66258
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to assign stdout to variable?

Post by admin »

The command box flashing should be gone with the next release... :)

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How to assign stdout to variable?

Post by klownboy »

Thanks Don.

binocular222
Posts: 1423
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: How to assign stdout to variable?

Post by binocular222 »

it seems windows shell is faster than piping through Mediainfo

Code: Select all

return property("#283", <cc_item>)
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: How to assign stdout to variable?

Post by LittleBiG »

admin wrote:... Damn, I'm spending too much time on this... :whistle: :biggrin:
Thanks for it. I do like this feature. :appl:

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How to assign stdout to variable?

Post by klownboy »

binocular222 wrote:it seems windows shell is faster than piping through Mediainfo
Thanks binocular222. I had assumed there was no "property" or "special property" available for video size based on what Huidong said in the first post of this tread, "...Custom Columns / Scripted Columns. I like it very much that image dimensions can now be displayed in a column, but not video dimensions." So, I never bothered to look fo myself. :) In a little CC script this will give the height and width.

Code: Select all

 return property("#283", <cc_item>) . "x" . property("#285", <cc_item>);
Thanks,
Ken

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: How to assign stdout to variable?

Post by Huidong »

klownboy wrote:
binocular222 wrote:it seems windows shell is faster than piping through Mediainfo
Thanks binocular222. I had assumed there was no "property" or "special property" available for video size based on what Huidong said in the first post of this tread, "...Custom Columns / Scripted Columns. I like it very much that image dimensions can now be displayed in a column, but not video dimensions." So, I never bothered to look fo myself. :) In a little CC script this will give the height and width.

Code: Select all

 return property("#283", <cc_item>) . "x" . property("#285", <cc_item>);
Thanks,
Ken
Thanks for pointing that out!

I should say the advantage of using MediaInfo however is two-fold:

1. Extensive video format support independent of the presence of codecs in the system. The frame height / width properties will work only if the corresponding codecs are installed system wide, which I wouldn't prefer doing for all sorts of other video files that Windows doesn't support out of the box, e.g. flash, mkv, webm, qt, even legacy real media, and so on, I wouldn't want to install any messy codec packs. That's why I only use a portable media player that is independent of system codecs as well.

2. Video dimensions is a tiny fraction of the info you can get out of the tool, for example, you also get to know bit rate, frame rate, the codec used, the writing library, the duration, etc, that you can't find natively via XY. So basically we just take the advantage of the expertise of third-party utilities. (Well, Don did that for Zip integration already, oh, and IFilters for full-text search, etc.)

Now beyond MediaInfo, how about pdfinfo? Or whatever other file types you work with often, you don't expect XY to always support them out of the box. Now with runret coming, it truly opens up a new world to bring whatever expertise from external power tools into XY without any hacking around, and you just do scripting from there. Normally I could imagine only developers enjoy the privilege of doing this level of things, but now pretty much all regular XY users can do it as long as they reading the Scripting documentation a little. What an excitement!

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: How to assign stdout to variable?

Post by klownboy »

Totally agree Huidong, MediaInfo certainly provides extensive info on media files. I spent some time yesterday going through some of the command line help. Though when you're after something relatively simple like a frame rate or size and it is available in "special properties" or "properties" it will probably be faster. This new runret is great for use with another I would say equivalent CLI executable, but for image files - ImageMagick - especially your photos. Previously I had this line in a image menu...

Code: Select all

run """cmd"" /C """"D:\Graphics\ImageMagick\identify.exe"" -verbose ""<curitem>"" | clip""",,2,0; text "<clipboard>", 700, 900, "Image Magick Info";
Now it's this...

Code: Select all

text runret ("D:\Graphics\ImageMagick\identify.exe -verbose ""<curitem>"""), 700, 900, "Image Magick Info";

Post Reply