Page 2 of 2

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 18:47
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");

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 18:51
by Huidong
Holy moly, can't wait!

Thank you, Don!

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 19:05
by bdeshi
Wheeeeeeeeeeeeeeeeeeeeeeeee! :biggrin: :biggrin: :biggrin:

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 19:50
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]

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 20:01
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 ;)

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 22:21
by admin
Okay, next beta will see some improvements here. Damn, I'm spending too much time on this... :whistle: :biggrin:

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 22:42
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:

Re: How to assign stdout to variable?

Posted: 03 Jun 2014 22:49
by admin
The command box flashing should be gone with the next release... :)

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 01:58
by klownboy
Thanks Don.

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 05:44
by binocular222
it seems windows shell is faster than piping through Mediainfo

Code: Select all

return property("#283", <cc_item>)

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 09:42
by LittleBiG
admin wrote:... Damn, I'm spending too much time on this... :whistle: :biggrin:
Thanks for it. I do like this feature. :appl:

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 13:16
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

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 17:33
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!

Re: How to assign stdout to variable?

Posted: 04 Jun 2014 18:39
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";