Cat command. SPod doesn't execute.

When i try to execute those lines:

COMPRESS ‘cat /transfer/arquivo > /transfer/saida’ INTO #CMD
CALL ‘shcmd’ #CMD

Nothing happens. The SPod doesn’t return anything.
Is it possible to execute commands like “echo”, “vi” and “cat”, from a natural program in the natural single point?

Hi Naira
You can execute shell commands even if the program runs under SPoD. There is just no terminal the shell can print its output. Try following:


CMD := 'pwd > /tmp/aaaa'      
CALL 'shcmd' CMD 

and check if the file /tmp/aaaa has been created and contains the pwd output.

Hi Klaus,

this command works. But I still need to edit a file in unix directory.

To see it, I’m using work file and “display” command. It works fine. But I’m still trying to find out how to edit it.

Thank you.

Hi Naira
There is no possibility I’m afraid.
If you run under SPoD you do not have a terminal on the server.
The Natural IO, which usually is routed to the terminal, is intercepted by SPoD and sent back to the client for displaying. But it is not possible to intercept the data the shell routes directly to the terminal.

May be it is an option to upload/download the file with Entire Connection:


0040 DEFINE WORK FILE 1 '/tmp/aaaa' TYPE 'ASCII'
0050 DEFINE WORK FILE 2 TYPE 'TRANSFER'
0060 INPUT 'a'
0070 SET CONTROL '+'
0080 READ WORK FILE 1 REC
0090 DOWNLOAD PC 3 REC
0100 END-WORK

Now edit the file on PC and upload the data.

An other approach could be to process the file editing using a Natural program


0050 DEFINE WORK FILE 1 '/tmp/aaaa' TYPE 'ASCII'
0060 READ WORK FILE 1 REC(I)
0070   ADD 1 TO I
0080 END-WORK
0090 CLOSE WORK 1
0100 /* input processing
0110 FOR I 1 100
0120   WRITE WORK 1 REC(I)
0130 END-FOR  

Cheers
Klaus

What’s the content of RET(“SHCMD”) after your call?
Maybe the natural-process doesn’t have the right to write into directory /transfer. To find this out, please redirect the Error-Output of your command into a separate file. Like this:

COMPRESS 'cat /transfer/arquivo > /transfer/saida 2>/tmp/error.log' INTO #CMD
CALL 'shcmd' #CMD

What’s the content of /tmp/error.log afterwards?

echo and cat should work. vi doesn’t work, because it’s an interactive program. But you can use a “batch editor” like sed instead. Example:

sed 's/old/new/g' /tmp/input.txt > /tmp/output.txt

Explanation: Replace “old” in file input.txt with “new” and write the output to output.txt. Of couse sed can do much more things than replacing …

Hi Mathias,

I tried this command:

COMPRESS ‘cat /transfer/arquivo 2>/tmp/error.log’ INTO #CMD

and the error.log was like:

cat: write error: Input/output error

Until now, I solve it using sysmain. The file is imported to natural, edited and sent back to directory. But isn’t an elegant solution.

Any more help will be welcome.

Thank you all.

That proofs: Natural executes the command “cat”, but the command fails.

I guess you will get the same error, if you execute your command on the Linux/Unix command line… If so, it’s not Natural’s error.