How to run shell command and paste its output?  SOLVED

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
jerry_goyal
Posts: 7
Joined: 11 Apr 20, 13:11

How to run shell command and paste its output?

Post by jerry_goyal » 06 Feb 21, 21:57

I'm having trouble setting up phraseexpress to run bash shell command and paste its output to text field. I looked all over the forums and docs but found no solution whatsoever.

For example, I want to paste the output of `curl 'https://api.ipify.org'` using bash shell on Windows.

Type: Run program
File Path: C:\Program Files\Git\bin\bash.exe
Parameters: curl 'https://api.ipify.org'

Actual output: opens bash terminal window briefly and then closes.
Expected output: paste the output of command `curl 'https://api.ipify.org'` to the text field.

It would open lots of possibilities if we could run bash/powershell/wsl commands and process output into text fields.

Peter Stotz
PhraseExpress Expert
Posts: 920
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 08 Feb 21, 21:05

@ jerry_goyal
Maybe it helps if you use the #focus-macro before inserting in the input field?
Peter Stotz
Windows 10 - PhraseExpress v15.0.81

jerry_goyal
Posts: 7
Joined: 11 Apr 20, 13:11

Post by jerry_goyal » 08 Feb 21, 23:15

I don't think that would work because the text is not available at all for pasting it into applications. the command `curl 'https://api.ipify.org'`when executed in bash shell gives the public ip address of PC for ex: (21.123.45.98). But here when using 'run program', phraseexpress is invoking the shell, passing this command as parameter and that's all. The output text is not carried at all to the phraseexpress.

jerry_goyal
Posts: 7
Joined: 11 Apr 20, 13:11

Post by jerry_goyal » 15 Feb 21, 11:58

Friendly ping. Is there any way to run bash/powershell commands and paste the output of commands back in the current application window?

Technical Support
Posts: 2798
Joined: 10 Feb 06, 22:23

Post by Technical Support » 15 Feb 21, 16:26

Well, a possible solution would be writing the output to a file:

Code: Select all

{#run -file "powershell.exe" -params "-command "curl 'https://api.ipify.org' | Select-Object -ExpandProperty Content > d:\out.txt"" -variablename Windows PowerShell}{#sleep 3000 -variablename Wait}{#insertfile D:\out.txt -variablename Output file}
It is just not very nice, that we cannot wait for the file, so a sleep for 3 seconds is used here.

jerry_goyal
Posts: 7
Joined: 11 Apr 20, 13:11

Post by jerry_goyal » 15 Feb 21, 18:11

Thanks, Although the instant flash of powershell window and 3 second timer ruins the beauty of automation.

May I suggest that shell scripting execution should be supported natively in PhraseExpress.

Technical Support
Posts: 2798
Joined: 10 Feb 06, 22:23

Post by Technical Support » 15 Feb 21, 18:16

You can decrease the wait time, of course.
We will add shell scripting support to our todo list.

Post Reply