sang1285
23rd October 2013, 15:19
Hi,
Is it possible to read the output of a unix shell command (run by shell() or run_prog() command) in the UI Script ?
mark_h
23rd October 2013, 15:24
Not sure you can do it directly, but you can write it to disk and read it back in.
george7a
23rd October 2013, 15:39
I agree with Mark. Let the shell script write its output on a file, and then make the baan script read it. You will have to wait for the shell script to finish.
sang1285
23rd October 2013, 15:48
Ok. Let me check that out.
Thanks for the replies :-)
JaapJD
24th October 2013, 09:48
If you are on Unix (as your profile says) and do not plan to move to Windows on short term :-) you can also use the pipe* functions.
vamsi_gujjula
24th October 2013, 14:32
Hi JaapJD,
just in case if you have any example for this pipe* function , Can please post it.
JaapJD
24th October 2013, 15:37
Following code sends a message for each file in /tmp:
function main()
{
long fp.pipe
long ret.io
string line(200)
fp.pipe = pipe.open("ls -l /tmp/*", "r")
if fp.pipe then
while not pipe.eof(fp.pipe)
ret.io = pipe.gets(line, 200, fp.pipe)
message(line)
endwhile
ret.io = pipe.close(fp.pipe)
endif
}
NPRao
30th October 2013, 02:42
Is it possible to read the output of a unix shell command (run by shell() or run_prog() command) in the UI Script ?
Yes, the run.prog() allows you to capture the output. The online programmer's manual on the site is not up to date.
run.prog()
Syntax:
function long run.prog (const string progname, const string arguments, long mode [, string stdin] [, string stdout] [, string stderr])
Description
The function run.prog() runs an operating system command. It is a system-dependent function. It must not be used in applications that are distributed across different platforms.
Arguments
const string progname The name of the program or command to be executed. run.baan.prog() expands progname to $BSE/bin/ progname { release}.
If the progname argument in run.prog() does not supply the full path (absolute or relative), the system searches for the command using the standard facilities of the operating system platform (for example, under UNIX, all PATH elements are searched).
The argument can specify a remote host. For example, if progname is "tahoe!sort", the function runs the sort program on the tahoe host. The maximum number of remote programs that can run concurrently depends on available system resources.
const string arguments The function start the program or command with the parameters specified here.
long mode This specifies the execution mode of the program or command. The possible values are:
RP_WAIT wait for the program to finish
RP_NOWAIT run as a background program
[string stdin] Reads input from the file named stdin. (The default value is "", which gives the program no input.)
[string stdout] Writes output to the file named stdout. (The default value is "", which ignores all output from the program.)
[string stderr] Writes error messages to the file named stderr. (The default value is "", which ignores all error messages from the program.)
Return values
0 program executed successfully
<0 program could not be started
>0 program did not execute successfully
Note that the return value cannot be retrieved when the mode argument is set to RP_NOWAIT.
Context
This function is implemented in the porting set and can be used in all script types.
Note
Input for the program cannot be entered interactively, but it can be read from a file. There are two ways to do this:
Use the stdin argument described above.
If the program has a command line argument for input redirection, pass this in the arguments argument to let the program read from a file.
Output or error messages from the program cannot be displayed, but they can be stored in a file. There are two ways to do this:
Use the stdout and stderr arguments described above. (Please note that the previous contents of these files is lost.)
If the program has a command line argument for output/error redirection, pass this in the arguments argument to let the program send results to a file. (For example, several Baan programs accept -q, -qo, and/or -qe arguments.)
Use these functions instead of the shell() function used in previous versions of BAAN.
I have used it many times on Unix.
e = run.prog("wc", "-l", RP_WAIT, ifile, fname, fname)
e = run.prog("cd " & fpath & ";split", "-a8 -l "& str$(line.count) & " xxx", RP_WAIT, ifile, fname, fname)
The simple usage is -
e= run.prog(comd, args, RP_WAIT, inputfile, outputfile, errorfile)
I like Jaap's solution too, which gives step-by-step output as processed.
sang1285
30th October 2013, 15:01
Perfect !! Thank you JaapJd and NPRao ...
I tried both the solutions... :-)