Capture and Display Command Output

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee

Capture and Display Command Output

Post by VeeGee »

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: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Capture and Display Command Output

Post by highend »

runret() is your friend...
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Capture and Display Command Output

Post by VeeGee »

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 747 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 747 times
Back to the manual/forum search to see what I can come up with. Getting closer.

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Capture and Display Command Output

Post by highend »

Hint: Easiest way = cmd /c with parentheses syntax...
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Capture and Display Command Output

Post by VeeGee »

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 737 times
Display this :
Image-005.png
Image-005.png (3.51 KiB) Viewed 737 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: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Capture and Display Command Output

Post by highend »

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

Post Reply