Re: How to run unix command using system()?
- From: rtsujimoto_consultant@xxxxxxxxxxxxxx
- Date: Mon, 02 Jul 2007 07:49:23 -0700
On Jun 29, 6:10 pm, Thomas <tho...@xxxxxxxxxxx> wrote:
rtsujimoto_consultant wrote:
In unix, I can do:
system("ls -l > ls_list.tmp");
But, on AS/400 the system() and Qp0zSystem() supposedly only run CL
commands. Is there a way to accomplish the above?
In Unix, the "system" is Unix; so, the system utility runs Unix commands
from within a shell. You wouldn't expect it to run an i5/OS command. In
i5/OS, the "system" is i5/OS; so, system runs i5/OS commands from within
a shell. Whether in Unix or i5/OS, the system utility doesn't directly
run commands for a different system.
In i5/OS, if you want to run Unix-like utilities, use QSH or STRQSH
instead of system. E.g.:
==> qsh 'ls -l > ls_list.tmp'
Note that the [>] redirection character is not part of the ls utility.
It is a shell operator and must be interpreted by the shell. The QSH
command invokes the qsh shell and runs the supplied command. The example
command starts the qsh shell and runs the ls utility.
Setting the QIBM_QSH_CMD_OUTPUT environment variable before running a
STRQSH command will help you to control what happens to STDOUT output
while the utility is run. In your example, you are redirecting STDOUT
anyway.
STRQSH sends a completion message when it ends, to help you track the
result. Setting the QIBM_QSH_CMD_ESCAPE_MSG environment variable lets
you choose whether you would get *ESCAPE messages instead.
Your example used a single utility. You can run a series of utilities by
separating them with semi-colons (";"). The parameter to STRQSH can be
up to 5000 characters long, so you put a whole bunch of utilities into
the string.
Qshell provides one of the Unix-like shells available under i5/OS. Other
shells are available in the PASE environment. Either Qshell or PASE (or
both) must be one of the installed options of i5/OS before one can be
started.
--
Tom Liottahttp://zap.to/tl400
Sorry guys, but I was off for a couple of days, so I didn't have a
chance to review the replies. Anyway, I tried the following:
system("qsh cmd('/usr/bin/ls -l > /mqm/ls_listmp')");
and
QzshSystem("/usr/bin/ls -l > /mqm/ls_listmp");
The former worked, but QzshSystem didn't. strerror(errno) showed "No
such path or directory" Strange.
.
- Follow-Ups:
- Re: How to run unix command using system()?
- From: Thomas
- Re: How to run unix command using system()?
- Prev by Date: Re: OS400/Cobol versus Micro Focus Cobol
- Next by Date: Using spawn() to capture output of child process
- Previous by thread: Re: OS400/Cobol versus Micro Focus Cobol
- Next by thread: Re: How to run unix command using system()?
- Index(es):
Relevant Pages
|