rob@xxxxxxxxx wrote:
I suppose if you get really good at this you can figure out how to do
something like
ls '/home/drasch' || system CPYFRMIMPF ...
and pipe the output directly into CPYFRMIMPF but I only know enough to
send you on a wild goose chase.
To pipe the output somewhere, you'd have to use a single pipe.
ls '/home/drasch' | system CPYFRMIMPF ...
the double-pipe you used would only run the "system" command if the "ls"
command ended in error. :) (I know that's not what you were going for)
The big problem with this scenario is that CPYFRMIMPF isn't a Unix
command and doesn't read STDIN looking for a list of filenames... You
have to specify the filename in the FROMSTMF parameter, not pipe it to
STDIN...
If you really wanted a (poor performing) way of doing the whole shebang
from QShell, you could use the "find" utility. "find" has the
capability of running a command for every file that matches a given
pattern. For example (this should be all one line -- though I'm sure
the e-mail software will wrap it):
find /home/klemscot -name '*.csv' -exec system "cpyfrmimpf
fromstmf('{}') tofile(mylib/myfile) rcddlm(*all)" \;
This tells the 'find' utility to search the /home/klemscot folder of the
IFS. It will find all files that match the pattern *.csv (make sure
that's in quotes, as I have it above, otherwise QShell will treat the *
as a special character and you'll have anarchy). The -exec parameter
tells it to execute a command for every file that it finds.
in this case, it executes the QShell "system" command, which runs a CL
command. The \; signals the end of the command you want the -exec
switch to run.
The {} characters in the middle of the command string will be replaced
with the filename that the "find" utility finds. It will submit a new
job for each file that it finds, so if there are many that match the
wildcard, this will perform poorly. If you only expect one or two that
match, this is probably okay.
Personally, I wouldn't do it this way because of the performance.
Another problem with this approach is error handling... it's hard to do
a good job of handling errors that might occur on the CPYFRMIMPF command.
Then, there's the fact that you'll have to understand Unix shell
scripting well enough to write/maintain the code... Let's use Rob's
example (since I don't think Rob will be offended if I pick on him)
This was his first example:
system dspf /rob/duh.txt
This is perfectly valid as far as Qshell is concerned. But it leaves
you with "dspf /rob/duh.txt" being passed to the native command-line.
You can't have a / character in a native command line unless it's put in
quotes... quotes is where the headaches will start.
Rob's second example:
system dspf '/rob/duh.txt'
Qshell will assume those quotes are meant for Qshell, not to be passed
to the native command. The single quotes are "strong quotes" and mean
that the contents inside them are not to be taken as special characters.
So QShell will pass /rob/duh.txt directly to the native command
interpreter without trying to interpret them further -- which is okay,
except that Qshell will strip the single quotes off of the command first
-- so we're right back to the first error. This is what gets passed to
QCMD: dspf /rob/duh.txt
Back to square one, / being in the command without quotes surrounding
it. Whenever you go through multiple command interpreters (both QShell
and QCMD in this case) things get ugly like this.
Rob's next example:
system DSPF STMF('/rob/duh.txt')
Both the single quotes, and the parenthesis here will be interpreted as
special characters by QShell. The parenthesis aren't in a valid place
for QShell to use them, so you get the "token not expected". If they
had been in the right place for Qshell, you'd have the same problem as
before... the quotes would be stripped before sending it to QCMD.
The solution is easy, just put double quotes around the whole thing.
Then QShell won't try to do any special interpretation of the single
quotes or the parenthesis...
system "DSPF STMF('/rob/duh.txt')"
This is now syntactically legal... but now you have a new problem! DSPF
is an interactive 5250 command, and QShell submits a background job (BCI
job) to run the command. So it'll fail with "DSPF not allowed in this
setting" since you can't run DSPF in a batch job.
However, if you used CPYFRMIMPF or another command that's allowed in
batch, this syntax would work... If you followed all of that, you'll
see why I used the syntax that I did in the "find" example. But the
next person to maintain your code may not understand all of this.
So that, plus performance, etc, etc, is why I'd recommend using the IFS
APIs or having QShell output to a file, then read the file from CL.
It's just easier...
this is getting too long, so I'll stop here.
As an Amazon Associate we earn from qualifying purchases.