Page 1 of 1

Capture and Display Command Output

Posted: 20 Mar 2019 20:24
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.

Re: Capture and Display Command Output

Posted: 20 Mar 2019 20:38
by highend
runret() is your friend...

Re: Capture and Display Command Output

Posted: 20 Mar 2019 21:04
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
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
Back to the manual/forum search to see what I can come up with. Getting closer.

Re: Capture and Display Command Output

Posted: 20 Mar 2019 21:42
by highend
Hint: Easiest way = cmd /c with parentheses syntax...

Re: Capture and Display Command Output

Posted: 20 Mar 2019 23:08
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
Display this :
Image-005.png
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).

Re: Capture and Display Command Output

Posted: 20 Mar 2019 23:39
by highend
This would have worked as well:

Code: Select all

text runret("cmd /c (openssl dgst -sha256 -binary ""<curitem>"" | openssl base64 -A)");