Re: How to run unix command using system()?



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.

.



Relevant Pages

  • Re: Lisp/Unix impedance [a programming challenge]
    ... >> I don't think you even have any idea what Unix is. ... nice if using a command shell under Windows didn't feel like working ... with blinders on a command line that's been made deliberately hard to ... An Emacs over a *nix shell is pretty usable at controlling ...
    (comp.lang.lisp)
  • Re: "Under z/OS Unix"
    ... task is running under have UNIX credentials. ... Unix command binaries can be invoked by BPXBATCH/COZBATCH (see ... The former is then referring to the shell built in commands and the ... I'd prefer "The shell can be run interactively, via TSO OMVS..." ...
    (bit.listserv.ibm-main)
  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)
  • Re: problems w/ my MAC OS 10.5.7 unix?
    ... The unix described there ... differs from that on my Mac. ... Mac OS X no longer makes the tcsh shell default (I think it did up ... case, after freshly launching Terminal and typing the "ps" command, the ...
    (comp.sys.mac.programmer.help)