From: Humbel O. <Otm...@bi...> - 2001-12-03 07:38:18
|
[ Kevin Butler ] > > On the positive side, I can type > > >>> import os > > >>> os.system( 'env' ) > > >>> os.system( 'java' ) > > and get the correct output. >=20 > Wow - I certainly wasn't expecting that! :-) >=20 > I believe that is using 'sh' as its sub-shell. Interesting -=20 > can you run 'sh' from the normal AS/400 shell? Yes and no. From the native shell, I have to type STRQSH to get a POSIX-like shell named Qshell http://www.as400.ibm.com/developer/qshell/ Once there, I can type: env sh -c env qsh -c env all resulting in the same output. Now, using the latest checked in version from javaos.py, I get (the output of alias is not human readable): Jython 2.1a3 on java1.3.0 (JIT: NONE) Type "copyright", "credits" or "license" for more information. >>> $ import os >>> $ os.system( 'alias' ) =A3 ~ =A7@`=C1% 0 >>> I managed to translate the output correctly to=20 >>> $ os.system( 'alias' ) tar=3Dpax -A 0 >>> =20 > Could you please send me the output of the following? (You=20 > may need javaos.py v2.12 from CVS - I did some renaming to=20 > make things more consistent with other modules) >=20 > >>> import os > >>> print os._shellEnv.getEnv, os._shellEnv.cmd,=20 > os._shellEnv._formatCmd( "echo hello world" ) >=20 > I expect it to print: > env ['sh', '-c'] ['sh', '-c', 'echo hello world'] Here it is (your version): $ print os._shellEnv.getEnv, os._shellEnv.cmd, \ os._shellEnv._formatCmd( "echo hello world" ) env ['sh', '-c'] ['sh', '-c', 'echo hello world'] >>> > Some ideas (brainstorm mode): > - a problem with quoting? try os.system( '"java -version"' ) Ooops, now I remeber once quoting all but the command itself: $ os.system( 'java "-version"' ) nicely prints the output.... see your comments on echo below ! > - a problem with the encoding of the space or the hyphen? =20 > maybe try a "java helloWorld"? > - a path problem (different java executables?) > - from the shell, can you do (I don't know if the "" is right=20 > to keep the command in a single arg on AS/400...): =20 > sh -c "java -version" Yes, without a problem. < snipped suggestions about Runtime.exec() >=20 > > 4. > > >>> os.system( 'echo hello' ) > > gives no output at all - difficult to pass os.__test() this way :-( >=20 > Yip, I added those tests when I discovered similar behavior... :-) >=20 > This is probably the same problem as #3 - the secondary=20 > arguments are not getting passed correctly to echo command,=20 > so echo is cheerfully echoing a blank line... >=20 > When I encountered this behavior, I was working with the=20 > String form of Runtime.exec, executing strings like 'sh -c=20 > "my command"' and the behavior was different on NT,=20 > NT-cygwin, and Linux - some of those platforms worked with=20 > the quoted command, others would fail with the quotes, but=20 > give the 'one command, no args' behavior you're seeing if=20 > they didn't have the quotes. =20 >=20 > Using the exec( String[] ) form works better, because you=20 > specify the argv array for the shell w/o worrying about=20 > quoting, so the shell gets exactly: "-c", "java -version",=20 > ... At least in theory... I still haven't found a combination to get this echo.=20 So I will further investigate, using your suggestions. And trying to solve the different encodings.. I'll attach javaos.py - but do not checkin yet, please :-) to give you an idea what I am doing. The basic change is to use a subclass _QShellEnv of _ShellEnv which handles all the os400 specifics. Best wishes, Oti. |