PxPlus User Forum

Main Board => Discussions => Language => Topic started by: Lawrence_Leavell on June 29, 2019, 06:08:36 PM

Title: Windx Linux Shell Commands
Post by: Lawrence_Leavell on June 29, 2019, 06:08:36 PM
In the client/server Windx environment with a Linux server, how are shell scripts executed from a Windx Business basic process?
Title: Re: Windx Linux Shell Commands
Post by: Devon Austen on July 02, 2019, 09:07:33 AM
The INVOKE directive allows you to pass a command off to the operating system.

INVOKE "cat my_file | grep 'serach string'"

If you want the send the Windows workstation the command prefix with [wdx] or [lcl]

https://manual.pvxplus.com/?directives/invoke.htm

 
Title: Re: Windx Linux Shell Commands
Post by: Lawrence_Leavell on July 03, 2019, 03:25:55 PM
OK, use invoke.  In that case, how do I test the return response from Linux?
Title: Re: Windx Linux Shell Commands
Post by: Devon Austen on July 03, 2019, 04:09:51 PM
If you want to read back the result you can use pipe IO instead i.e.

OPEN (chn)"<cat my_file | grep 'serach string'"
read record (chn) result$

You then can keep doing reads until you get an EOF.

You can use INVOKE, but if you want the result you need to redirect it to a file and read the file.

INVOKE "cat my_file | grep 'serach string' > result"
open (chan)"result"
read record (chn) result$
Title: Re: Windx Linux Shell Commands
Post by: John_S on July 03, 2019, 05:10:13 PM
We use the EXECUTE command.

48110 LET XX$="A=SYS("+$22$+"/data/DATAMpvx/emailer.pl '"+WHOFM$+"' '"+EMAIL$+"
48110:' '"+ATTACHMENT$+"' '"+SUBJ$+"'"+$22$+")"
48120 EXECUTE XX$

The above invokes a Perl script to send an e-mail. The script returns a 0 or 1 to our variable A, which we can test to see if the mail was sent successfully.
Title: Re: Windx Linux Shell Commands
Post by: Mike King on July 03, 2019, 05:50:04 PM
John,

Why the EXECUTE?

You could just have easily done:

48110 A=SYS("/data/DATAMpvx/emailer.pl '"+WHOFM$+"' '"+EMAIL$+"' '"+ATTACHMENT$+"' '"+SUBJ$+"'")

Then just test A... or use the SYS function as the subject of an IF.

The extra EXECUTE seems redundant and forces the system to compile the command prior execution slowing things down.

Side note: I trust your logic makes sure all the fields cannot contain apostrophes -- for example you need to make sure the Subject line is not

  "Sorry, I can't come out and play"

The Apostrophe in "can't" will mess up your logic regardless of the EXECUTE or not.
Title: Re: Windx Linux Shell Commands
Post by: John_S on July 03, 2019, 06:01:13 PM
Hi Mike.

You are of course correct. I did not write this code - it is very, very old code. I only provided it as an example for Lawrence to illustrate another method of obtaining what he is looking for.