View previous topic :: View next topic
|
Author |
Message |
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Hello,
I am using the following code which I found in an IBM link to display the current working directory and list the contents of a directory that I specify as a parameter or after a prompt.
Code: |
/* rexx */
parse arg dir
address syscall 'getcwd cwd'
say 'current directory is' cwd
if dir=' ' then
do
say 'enter directory name to list'
parse pull dir
end
'ls -l' dir
return
|
I am getting the follwing output.
Code: |
current directory is /
enter directory name to list
/stcell
IKJ56500I COMMAND LS NOT FOUND
11 *-* 'ls -l' dir
+++ RC(-3) +++
|
The 'ls -l' command is not working.
Can anybody tell me what is wrong with this?
Thanks |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You are executing the -ls command in whatever environment is your default. You need to kick it down to the Unix operating system in the same way as you did the getcwd, at a guess. |
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Hello
I am able to display the contents of OMVS file using below code
Code: |
FN = abc.xyz.123
CALL SYSCALLS 'ON'
ADDRESS SYSCALL
'readfile '||FN||' list. '
DO I = 1 TO LIST.0
say list.i
end |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Are you saying you still have a problem? Or are you saying "I can do this, but still can't get the -ls to work"? |
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Quote: |
Are you saying you still have a problem? Or are you saying "I can do this, but still can't get the -ls to work"? |
Thanks Bill.
What I meant was I am able to read the contents of a particular file using the readfile command.
But I am unable to use 'ls -l'
its giving output as command not found. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Did you try
Code: |
address syscall 'ls -l' |
Or simply try after your "address syscall" with no parameters, like in your second snippet?
If you have a way to get one unix command working, that will work for another. With your existing ls, you are not sending it off to another environment (unix) but just trying it whereever you happen to be at the time. |
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Bill,
I tried this code..
Code: |
trace i
PARSE ARG DIR
CALL SYSCALLS 'ON'
ADDRESS SYSCALL 'getcwd cwd'
SAY 'CURRENT DIRECTORY IS' CWD
IF DIR=' ' THEN
DO
SAY 'ENTER DIRECTORY NAME TO LIST'
PARSE PULL DIR
END
ADDRESS SYSCALL 'ls -l'
RETURN |
output:
Code: |
3 *-* PARSE ARG DIR
>>> ""
4 *-* CALL SYSCALLS 'ON'
>L> "ON"
>>> "0"
5 *-* ADDRESS SYSCALL 'getcwd cwd'
>L> "getcwd cwd"
6 *-* SAY 'CURRENT DIRECTORY IS' CWD
>L> "CURRENT DIRECTORY IS"
>V> "/"
>O> "CURRENT DIRECTORY IS /"
CURRENT DIRECTORY IS /
7 *-* IF DIR=' '
>V> ""
>L> " "
>O> "1"
*-* THEN
8 *-* DO
9 *-* SAY 'ENTER DIRECTORY NAME TO LIST'
>L> "ENTER DIRECTORY NAME TO LIST"
ENTER DIRECTORY NAME TO LIST
10 *-* PARSE PULL DIR
/stcell
>>> "/stcell"
11 *-* END
12 *-* ADDRESS SYSCALL 'ls -l'
>L> "ls -l"
+++ RC(-20) +++
13 *-* RETURN |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
And don't you feel that that is an improvement?
You don't get a mainframe message any longer, so a step forward.
Your getcwd is showing a "root" directory. You don't do anything to change the directory to the one requested/passed as an argument. So your -ls is going to the root. My guess would be you don't have permission for -ls on the root.
Why don't you now include the directory on your -ls (like you had before), or change directory to the one supplied and do the -ls (perhaps better, then you don't have to include the directory on every command).
Have a look back in the rexx forum, by the way, for a post from enrico showing a "wrapper" technique. It is a really good way to manage things. If you do all your "address" stuff to seperate pieces of correct code you'll find things go more smoothly. |
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Hello,
Quote: |
Why don't you now include the directory on your -ls (like you had before), or change directory to the one supplied and do the -ls (perhaps better, then you don't have to include the directory on every command). |
I tried that too. Still getting RC(-20)
Quote: |
, for a post from enrico showing a "wrapper" technique. |
Will read abt this now and see if it can help here.
Thanks |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
enrico's wrappers are a good method to ensure that you "external" (to rexx) commands always go to where they should, that you don't have 99 working correctly and another one popping off somewhere else.
Your original problem was the the "-ls" was not getting to the target system, because you didn't tell it to.
Now you are getting the "20". The command is arriving, but the "20" is telling you something.
If you can get the current-working-directory and can't list the contents of the directory, I think you have a "permissions" problem. That the logon which you are using does not have authority to do anything to the directory. If you know of a sub-directory that exists, can you change-directory to it? Are you able to make-directory?
Are you able to login with that id manually and try the ls? Are you able to find out what a 20 rc might mean from the unix underneath? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
when somebody does not read the manuals they usually get a -20 return code
in general a -20 return code from an Address SOMEENVIR "somecommand"
tells that the somecommand is not supported by the SOMENVIR environment
the manual
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/BPXZB680/CCONTENTS?DT=20080602214011
will tell what <commands> are supported by the SYSCALL environment
and certainly LS is not one of them
in this case the proper syntax would be tested and working
Code: |
Address SYSCALL "readdir / dir."
do i = 1 to dir.0
say dir.i
end
|
odd that
Code: |
Address SYSCALL "getcwd cwd"
say cwd
|
returns CWD verbatim ( an uninitialized variable )
in a FULL Unix environment the environment to be addressed for LS
would be certainly BASH or the equivalent for the shell being used
Code: |
Address BASH "ls / | rxqueue"
if RC \= 0 then exit
do while ( queued() > 0 )
parse pull z
say z
end
|
|
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
Thanks a lot enrico.
I will go thru the link and use the commands which are supported in SYSCALLS environment. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
rahul1586
New User
Joined: 04 Nov 2008 Posts: 28 Location: Mumbai
|
|
|
|
I found the code in
z/OS V1R12.0 Using REXX and z/OS UNIX System Services
SA22-7806-13
In the examples of using SYSCALLS command there is the example which I used Display the working directory and list a specified directory
My site has zOS v1r11 and this link is for zOS v1r12.
Could that be the reason that the command is not working at my site?
Anyway the same link has the SYSCALLS command descriptions which I can use in my code
Thanks |
|
Back to top |
|
|
|