PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Windx Linux Shell Commands  (Read 1994 times)

Lawrence_Leavell

  • Silver Member
  • ***
  • Posts: 49
    • View Profile
Windx Linux Shell Commands
« 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?

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Windx Linux Shell Commands
« Reply #1 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

 
Principal Software Engineer for PVX Plus Technologies LTD.

Lawrence_Leavell

  • Silver Member
  • ***
  • Posts: 49
    • View Profile
Re: Windx Linux Shell Commands
« Reply #2 on: July 03, 2019, 03:25:55 PM »
OK, use invoke.  In that case, how do I test the return response from Linux?

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Windx Linux Shell Commands
« Reply #3 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$
Principal Software Engineer for PVX Plus Technologies LTD.

John_S

  • Silver Member
  • ***
  • Posts: 20
    • View Profile
Re: Windx Linux Shell Commands
« Reply #4 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.

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Windx Linux Shell Commands
« Reply #5 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.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

John_S

  • Silver Member
  • ***
  • Posts: 20
    • View Profile
Re: Windx Linux Shell Commands
« Reply #6 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.