From: Kevin B. <kb...@ca...> - 2001-11-29 17:17:34
|
Humbel Otmar wrote: > > Hello Kevin, others. > > please let me give feedback how work is going on. > System.getProperty( "os.name" ) returns "OS/400", > I therefore suggest we stick to platform = "os400" from now on ... Great. > On the positive side, I can type > >>> import os > >>> os.system( 'env' ) > >>> os.system( 'java' ) > and get the correct output. Wow - I certainly wasn't expecting that! :-) I believe that is using 'sh' as its sub-shell. Interesting - can you run 'sh' from the normal AS/400 shell? Could you please send me the output of the following? (You may need javaos.py v2.12 from CVS - I did some renaming to make things more consistent with other modules) >>> import os >>> print os._shellEnv.getEnv, os._shellEnv.cmd, os._shellEnv._formatCmd( "echo hello world" ) I expect it to print: env ['sh', '-c'] ['sh', '-c', 'echo hello world'] > Open issues: > > 1. > Process.getInputStream() is in a foreign encoding (EBCDIC I guess), so I > have to decode it using a FilterInputStream. I made some exercises with > Per Gummedal's lib/encodings/ebcdic.py file from the CPython > implementation > http://home.no.net/pgummeda > but with no success. I'm not likely to be much help here. :-( > 2. > The two commands above produce a different stream encoding, e.g.: > env results in int value 37 for "\n", > java results in int value 21 for "\n" > Now I am searching for a way to handle that correctly. Or here. :-( But it is likely to make me wish I had gone ahead and refactored _ShellEnv._getEnvironment out into _getEnvironment and _parseEnvironment... :-) > 3. > I cannot yet type > >>> os.system('java -version') > meaning any command taking an argument (which is valid on the native > shell) leads to a 'invalid option' error message. Still searching here. Some ideas (brainstorm mode): - a problem with quoting? try os.system( '"java -version"' ) - a problem with the encoding of the space or the hyphen? 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 to keep the command in a single arg on AS/400...): sh -c "java -version" You could try messing around with Runtime.exec() directly to see what works (and this is suggesting refactoring _ShellEnv._system's "print the streams" logic into another method). from os import _shellEnv from java.lang import * p = Runtime.getRuntime().exec( ['sh', '-c', 'java -version'] ) # should be what is being done now print _shellEnv._readLines( p.getInputStream() ) print _shellEnv._readLines( p.getErrorStream() ) trying commands like ['sh', '-c', 'java', '-version'] # this would surprise me ['sh', '-c', '"java -version"'] # in case Runtime.exec is doing some quote processing? 'sh -c "java -version"' # use the (String) form of exec, in case exec does some other quoting... # Using echo may give some info on how args are being processed/passed to the sub-process ['echo', 'sh', '-c', 'java -version'] ['echo', 'sh', '-c', 'java', '-version'] ['echo', 'sh', '-c', '"java -version"'] 'echo sh -c "java -version"' You may also write a little C program something like: int main( int argc, char **argv ) { int i; printf( "argc: %d", argc ); for ( i = 0; i < argc; i++ ) printf( "argv[%d]=%s", i, argv[i] ); return 0; } and use it like 'echo' above to see how it is seeing the arguments passed to 'exec'... > 4. > >>> os.system( 'echo hello' ) > gives no output at all - difficult to pass os.__test() this way :-( Yip, I added those tests when I discovered similar behavior... :-) This is probably the same problem as #3 - the secondary arguments are not getting passed correctly to echo command, so echo is cheerfully echoing a blank line... When I encountered this behavior, I was working with the String form of Runtime.exec, executing strings like 'sh -c "my command"' and the behavior was different on NT, NT-cygwin, and Linux - some of those platforms worked with the quoted command, others would fail with the quotes, but give the 'one command, no args' behavior you're seeing if they didn't have the quotes. Using the exec( String[] ) form works better, because you specify the argv array for the shell w/o worrying about quoting, so the shell gets exactly: "-c", "java -version", ... At least in theory... kb |