From: Jean G. L. <ho....@te...> - 2005-06-08 14:33:08
|
Hi Georges, =20 Thanks a lot for your help. I did the same: =20 =20 public class CommandManager { public static String getOutputCommand( String command ) throws Exception { Process process =3D Runtime.getRuntime().exec( command ); process.waitFor(); BufferedReader in =3D new BufferedReader(new InputStreaReader(process.getInputStream())); String result =3D in.readLine(); in.close(); return result; } } =20 It works perfect when I use a local command on windows and unix. It still works when the command is a ssh on windows. But does not work anymore for a ssh command on unix. I don't get = anything! =20 >>> print CommandManager.getOutputCommand("/usr/bin/ssh = lalanne@mrs-dv-00001 cat ~/temp/result375.txt'" ) =20 None =20 =20 =20 But, on windows: =20 >>> print CommandManager.getOutputCommand("C:\\cygwin\\bin\\ssh.exe lalanne@mrs-dv-00001 'cat temp/result.txt'") =20 Serena ChangeMan Dimensions 9.1.0 at 13:39:34 Wednesday 08 June 2005 Copyright =20 =20 =20 So, now I am totally blocked. =20 I don=92t know how to get the output of my remote command =85 The problem is that I need this output! =20 Any help will be really appreciated. =20 Regards =20 Jean-Guillaume LALANNE =20 =20 -----Message d'origine----- De : George Rogers [mailto:gr...@so...]=20 Envoy=E9 : mercredi 8 juin 2005 16:01 =C0 : Jean Guillaume LALANNE Cc : 'Carlos Garcia'; jyt...@li... Objet : Re: [Jython-users] os.system and os.popen =20 I use Java directly to execute the command and get the output from the=20 Java exec method as shown below. You will probably want to change the command string=20 provided to the exec command. =20 Hope this helps. =20 # # function to look for an executable file in the search path and to=20 return its # full path. Uses the UNIX 'which' command and assumes UNIX OS # def getExecPath(prog): retPath =3D '' # set to return empty string cmdAr =3D ('which', prog) rt =3D java.lang.Runtime.getRuntime() proc =3D rt.exec(cmdAr) isr =3D java.io.InputStreamReader(proc.getInputStream()) bufferedReader =3D java.io.BufferedReader(isr) try: progInfo =3D bufferedReader.readLine(); if progInfo.startswith('/'): # looks like the right type of information retPath =3D progInfo except: bufferedReader.close() else: bufferedReader.close() return retPath =20 George Rogers =20 Jean Guillaume LALANNE wrote: =20 >Hi, >=20 >I have to run in one of my script a native command line. >I would like to get the output of this command. >How can I do since popen function is not yet implemented in jython ? >=20 >Thanks in advance for your help. >=20 >Regards, >=20 >Jean-Guillaume LALANNE >=20 >=20 >=20 >------------------------------------------------------- >This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput >a projector? How fast can you ride your desk chair down the office luge track? >If you want to score the big prize, get to know the little guy. =20 >Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=3D20 >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users > =20 >=20 |