Title: Call "system" Using Ws-command Includes Garbage
Description: Lawson add other WS garbage at the end
Keith_G_Thompson - September 12, 2006 06:27 PM (GMT)
While trying to run a CALL "SYSTEM" USING WS-COMMAND from within a custom program I am getting garbage at the end of the command. This appears to be leftover stuff from elsewhere in working storage.
I have seen this before and have been able to work around it, but never eliminate it. In this program I'm getting an error I can't seem to work around. Lawson support knowlege base has nothing on it (that I can find) and I haven't been able to find info in the forums.
The command I'm trying to run is actually a perl script that accepts a single command line parameter (filename) and then does a PGP encryption followed by an FTP. The script works fine and other programs are able to call and execute it just fine. In this case I can't even get the CALL "SYSTEM" statement to execute. In my new program I get something like this in my joblog: (most of the below is generated with DISPLAY statements)
********************** Job Log Excerpt **************************
Calling PGP & Send Script...
The following character string is too long:
D:\LINTE\APPS\scripts\benxfer.pl MYFILE work\MCBENFIL(very very long here->)
Called Script.
WS-SCRIPT: perl D:\LINTE\APPS\scripts\benxfer.pl <---ENDS HERE
WS-FILE-NAME: MYFILE <---ENDS HERE
WS-COMMAND: perl D:\LINTE\APPS\scripts\benxfer.pl MYFILE <----ENDS HERE
****************end excerpt***************************
The 2nd line is the error I'm looking at and comes exactly when I execute the statement:
CALL "SYSTEM" USING WS-COMMAND.
This error prevents the script from being called because the CALL "SYSTEM" never actually runs. You can see right after that I'm printing the value of WS-COMMAND and it ends as expected.
Where is that other garbage coming from?!? I've seen in the past Lawson tack on stuff like the full path of print files and work files, but in this case it seems to be adding on both the name and location of a work file as well as a data line from the file itself.
Explanations and resolutions welcome! :)
Keith (not a newbie - just new to the site!)
Milo - September 12, 2006 06:49 PM (GMT)
Keith:
Check your COBOL. How are you assembling the string to do the CALL? Are you intializing it first? Maybe you want to post some of your relevant code? (The GSC will charge you if you ask them to examine it. But you knew that.)
trezaei - September 12, 2006 07:29 PM (GMT)
Yeah, ditto what Milo said. You gotta initialize and it really matters how you string. A good example can be found in the post:
http://lawsontalk.com/index.php?showtopic=654if you're still not having any luck paste that section of your code here ...
T
Ragu - September 12, 2006 07:41 PM (GMT)
I always end my strings with a NULL ( WS-NULL PIC X VALUE X"00").
For instance, if I wanted to do a "ls" command, I would
STRING "ls" WS-NULL DELIMITED BY SIZE INTO WS-STRING.
CALL "system" USING WS-STRING.
This usually gets rid of any extraneous stuff.
Keith_G_Thompson - September 12, 2006 07:51 PM (GMT)
Thanks for the quick reply. I do not believe it has to do with my stringing of the command variable. (WS-COMMAND). I have initialized it directly before populating it and you can see in the joblog (above post) that I display WS-COMMAND followed by the string "<---ENDS HERE". This shows me that the variable itself if properly constructed and ends as expected. Somehow / somewhere Lawson is passing an additional variable during the system call.
****************** Source Code Extract ********************
IF (PRM-INT-SWITCH = "Y")
DISPLAY " "
DISPLAY "Calling PGP & Send Script..."
DISPLAY " "
STRING "perl " DELIMITED BY SIZE
SYSCMD-LAWDIR DELIMITED BY SPACE
WS-SCRIPT-DIR DELIMITED BY SPACE
INTO WS-SCRIPT
INITIALIZE WS-COMMAND
STRING WS-SCRIPT DELIMITED BY SIZE
" " DELIMITED BY SIZE
WS-FILE-NAME DELIMITED BY SIZE
INTO WS-COMMAND
CALL "SYSTEM" USING WS-COMMAND
DISPLAY " "
DISPLAY "Called Script."
DISPLAY " "
DISPLAY "WS-SCRIPT: " WS-SCRIPT "<---ENDS HERE"
DISPLAY "WS-FILE-NAME: " WS-FILE-NAME "<---ENDS HERE"
DISPLAY "WS-COMMAND: " WS-COMMAND "<----ENDS HERE"
END-IF.
**************** End Source Code *****************
We are on (unfortunately!) a windows environment 8.0.3 MSP#5 (I'm a unix bigot at a windows shop).
Additional thoughts & options?
Keith
Keith_G_Thompson - September 12, 2006 07:58 PM (GMT)
Hey, amazing. Thanks Ragu - that "null" approach worked great. New string command looks as follows:
********* Within WS ****************
02 WS-NULL PIC X VALUE X"00".
********** Within PD ****************
INITIALIZE WS-COMMAND
STRING WS-SCRIPT DELIMITED BY SIZE
" " DELIMITED BY SIZE
WS-FILE-NAME DELIMITED BY SIZE
WS-NULL DELIMITED BY SIZE
INTO WS-COMMAND
CALL "SYSTEM" USING WS-COMMAND
All done! (Much appreciation to the group. I will try to "pay you back" by submitting my own solutions from time to time)
Ragu - September 12, 2006 08:37 PM (GMT)
I am glad that worked. I have had similar problems while building file names too. Same solution.
trezaei - September 12, 2006 08:41 PM (GMT)
Cool, I'll have to add that to my bag of tricks. Glad to see the site has helped solve another mystery. Thanks Ragu.
Milo - September 13, 2006 01:13 PM (GMT)
Wow, I learned something too!
We have a 3rd-party interface in Lawson that I had to seriously rewrite a while back. It does some SYSTEM calls, which I don't particularly like, but I left them alone since they work fine. I checked just now -- sure enough, each and every string used in a SYSTEM call is assembled with a terminating "HEX-00".
I didn't know what that was for. Now I know. Thanks, Ragu and Keith! :thumb:
theking75 - March 7, 2007 04:42 PM (GMT)
I know I have built a successful Call “system” command before, but I can’t get it working today. It’s been a couple of years since I have written a program like this. Right now, all I have in the program is I am passing a CD command into a WS variable then I have the Call “system” but it is not executing the command. Do I have to have something else in the program for this to work?
theking75 - March 7, 2007 09:38 PM (GMT)
This is strange because I have a Win2000 box where the program works fine, but it doesn't run on a Win2003 box. Is there a problem with using the Call "system" command with Win2003?