Capture and Display Command Output

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee
Posts: 196
Joined: 27 Jul 2015 20:00

Capture and Display Command Output

Post by VeeGee » 20 Mar 2019 20:24

Good afternoon all,
Is it possible in XY to select file, run a script, capture the output and display it in a text box ?
For example, I have this :

Code: Select all

::SHA256;text hash("sha256",,1);
in my hamburger menu and it works great. I am using another tool (OpenSSL) on the command line to generate SRI hashes and wasn't sure if I could somehow have the results/output of this command displayed like the one listed above.
Command Line :

Code: Select all

openssl.exe dgst -sha256 -binary (selected file in XY) | openssl base64 -A

Code: Select all

openssl.exe dgst -sha256 -binary C:\Data\Repository\Projects\Web\jquery\jquery.js | openssl base64 -A
Sample Results :

Code: Select all

2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=
I just started reading about/applying SRI hashes to my local-only website resources (JS and CSS files). To generate the hashes, I've only seen online ones or the OpenSSL command line. Currently I am using the trick of putting in a bad hash in the script, let it fail so that Chrome displays the correct one in console.log and copy/paste it from there.

Was hoping there would be a way in XY to select a file and display the results for easier copy/pasting.

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Capture and Display Command Output

Post by highend » 20 Mar 2019 20:38

runret() is your friend...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

VeeGee
Posts: 196
Joined: 27 Jul 2015 20:00

Re: Capture and Display Command Output

Post by VeeGee » 20 Mar 2019 21:04

Thank you for the pointer. So far I have the pre-base64 portion working using this :

Code: Select all

::SRI;text runret("openssl dgst -sha256 -binary " . quote(<curitem>));
Pre-base64 results, these are good/correct:
Image-001.png
Image-001.png (2.9 KiB) Viewed 157 times
When I add the pipe I get the following error/message and the pipe is removed from code snippet:

Code: Select all

::SRI;text runret("openssl dgst -sha256 -binary " . quote(<curitem>) . " | openssl base64 -A");
Image-002.png
Image-002.png (4.88 KiB) Viewed 157 times
Back to the manual/forum search to see what I can come up with. Getting closer.

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Capture and Display Command Output

Post by highend » 20 Mar 2019 21:42

Hint: Easiest way = cmd /c with parentheses syntax...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

VeeGee
Posts: 196
Joined: 27 Jul 2015 20:00

Re: Capture and Display Command Output

Post by VeeGee » 20 Mar 2019 23:08

Got it working - thanks !
Using this :

Code: Select all

::SRI;text runret("""cmd"" /c openssl dgst -sha256 -binary ""<curitem>"" | openssl base64 -A");
Converts to this in my hamburger menu :
Image-006.png
Image-006.png (2.38 KiB) Viewed 147 times
Display this :
Image-005.png
Image-005.png (3.51 KiB) Viewed 147 times
Not sure if all the extra double-quotes are needed, I found something similar posted by you in another thread (when searching the forum for runret).

highend
Posts: 8304
Joined: 06 Feb 2011 00:33

Re: Capture and Display Command Output

Post by highend » 20 Mar 2019 23:39

This would have worked as well:

Code: Select all

text runret("cmd /c (openssl dgst -sha256 -binary ""<curitem>"" | openssl base64 -A)");
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

Post Reply