cmd = 'Dir C:\\program files ' -- zip files.zip file1 file2'
say 'the command is . . . . . ' cmd; r = Runtime.GetRuntime() p = r.exec(cmd) rc = p.exitValue() if rc <> 0 then do say 'Command "'cmd'" failed with rc:' rc'.' exit rc end My ?? is: How do I find out where things are? Is Runtime() to be imported or .... ?? Thanks for the time and enjoy the Day -- BobH PS: Day Light saving Time is a mess if you have two dozen clocks of various vintages; The Pendulum clocks are easy: In Fall you just stop the pendulum for an hour then restart it in motion -- gravity automagically takes over. But the others are something of a mess. When I had Kids or grand-kids around it was their job. _______________________________________________ Ibm-netrexx mailing list [hidden email] |
On 11/7/2010 11:09 AM, Robert Hamilton wrote:
cmd = 'Dir C:\\program files ' -- zip files.zip file1 file2'What operating system are you using? On Windows XP you need to use: p = r.exec("cmd /c" cmd) On other versions of Windows you use "command /c". You can determine which you need by opening the properties for the Command Prompt and looking at the executable. Start, All Programs, Accessories, Command Prompt, right click, Properties. Whatever application appears in the "Target" field is the command you need to invoke. You see, DIR is not an executable on Windows ... it's built in to the OS directly. Tom. _______________________________________________ Ibm-netrexx mailing list [hidden email] |
In reply to this post by Robert L Hamilton
Bob ;
There is nothing you need to import. However the Runtime class is quite difficult to use correctly. You will need to make a few changes and add some "streamgobblers" to prevent the command from hanging and also you need to wait for the command to complete. cmd = 'cmd /c dir "C:\\program files" ' -- zip files.zip file1 file2' say 'the command is . . . . . ' cmd; r = Runtime.GetRuntime() p = r.exec(cmd) errorGobbler = StreamGobbler(p.getErrorStream(), "ERROR") --// any error message? outputGobbler = StreamGobbler(p.getInputStream(), "OUTPUT") --// any output? errorGobbler.start() --// kick them off outputGobbler.start() rc = p.waitFor --rc = p.exitValue() if rc <> 0 then do say 'Command "'cmd'" failed with rc:' rc'.' exit rc end class StreamGobbler extends Thread is=InputStream type=String method StreamGobbler(is2=InputStream, type2=String) is = is2 type = type2 method run() public do br = BufferedReader(InputStreamReader(is)) line=String null line = br.readLine loop while line \= null System.out.println(type ">" line) line = br.readLine end catch ioe=IOException ioe.printStackTrace() end On 11/7/2010 9:09 AM, Robert Hamilton wrote: cmd = 'Dir C:\\program files ' -- zip files.zip file1 file2' _______________________________________________ Ibm-netrexx mailing list [hidden email] |
Thanks, Kermit; Same error: It cannot locate GetRunTime()
NetRexx portable processor, version 2.05 Copyright (c) IBM Corporation, 2005. All rights reserved. Program Qtime_Jr.nrx function Boilerplate(Rexx) [C:\NetRexx_Java\Doodles\Qtime_Jr.nrx 51 13 10] Error: The method 'GetRuntime()' cannot be found in class 'java.lang.Runtime' or a superclass Compilation of 'Qtime_Jr.nrx' failed [2 classes, one error] => Finished <= w/ your code. This is in jEdit BTW BobH On Sun, Nov 7, 2010 at 3:45 PM, Kermit Kiser <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] |
The method name is "getRuntime", not "GetRunTime". Java method names
are case sensitive. Rick On Sun, Nov 7, 2010 at 6:49 PM, Robert Hamilton <[hidden email]> wrote: > Thanks, Kermit; Same error: It cannot locate GetRunTime() > > NetRexx portable processor, version 2.05 > Copyright (c) IBM Corporation, 2005. All rights reserved. > Program Qtime_Jr.nrx > function Boilerplate(Rexx) > [C:\NetRexx_Java\Doodles\Qtime_Jr.nrx 51 13 10] Error: The method > 'GetRuntime()' cannot be found in class 'java.lang.Runtime' or a superclass > Compilation of 'Qtime_Jr.nrx' failed [2 classes, one error] > > => Finished <= > > w/ your code. This is in jEdit BTW > > > BobH > > On Sun, Nov 7, 2010 at 3:45 PM, Kermit Kiser <[hidden email]> wrote: >> >> Bob ; >> >> There is nothing you need to import. However the Runtime class is quite >> difficult to use correctly. You will need to make a few changes and add some >> "streamgobblers" to prevent the command from hanging and also you need to >> wait for the command to complete. >> >> cmd = 'cmd /c dir "C:\\program files" ' -- zip files.zip file1 file2' >> say 'the command is . . . . . ' cmd; >> r = Runtime.GetRuntime() >> p = r.exec(cmd) >> >> errorGobbler = StreamGobbler(p.getErrorStream(), "ERROR") --// any >> error message? >> outputGobbler = StreamGobbler(p.getInputStream(), "OUTPUT") --// any >> output? >> errorGobbler.start() --// kick >> them off >> outputGobbler.start() >> >> rc = p.waitFor >> --rc = p.exitValue() >> >> if rc <> 0 then >> do >> say 'Command "'cmd'" failed with rc:' rc'.' >> exit rc >> end >> >> class StreamGobbler extends Thread >> is=InputStream >> type=String >> >> method StreamGobbler(is2=InputStream, type2=String) >> is = is2 >> type = type2 >> >> method run() public >> do >> br = BufferedReader(InputStreamReader(is)) >> line=String null >> line = br.readLine >> loop while line \= null >> System.out.println(type ">" line) >> line = br.readLine >> end >> catch ioe=IOException >> ioe.printStackTrace() >> end >> >> On 11/7/2010 9:09 AM, Robert Hamilton wrote: >> >> cmd = 'Dir C:\\program files ' -- zip files.zip file1 file2' >> say 'the command is . . . . . ' cmd; >> r = Runtime.GetRuntime() >> p = r.exec(cmd) >> rc = p.exitValue() >> if rc <> 0 then >> do >> say 'Command "'cmd'" failed with rc:' rc'.' >> exit rc >> end >> >> My ?? is: How do I find out where things are? Is Runtime() to be imported >> or .... ?? >> >> Thanks for the time and enjoy the Day -- >> >> BobH >> >> PS: Day Light saving Time is a mess if you have two dozen clocks of >> various vintages; The Pendulum clocks are easy: In Fall you just stop the >> pendulum for an hour then restart it in motion -- gravity automagically >> takes over. But the others are something of a mess. When I had Kids or >> grand-kids around it was their job. >> >> >> >> _______________________________________________ >> Ibm-netrexx mailing list >> [hidden email] >> >> >> _______________________________________________ >> Ibm-netrexx mailing list >> [hidden email] >> >> > > > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > > > _______________________________________________ Ibm-netrexx mailing list [hidden email] |
In reply to this post by Robert L Hamilton
I don't think I can help you Bob - the code I posted runs fine on my
Win XP system and my Win7 64bit system both with NetRexxDE and
NetRexxScript under jEdit. Perhaps if you provide some details of
the environment you used and any classpath or options you set along
with the exact code you compiled, someone can figure it out.
-- Kermit On 11/7/2010 3:49 PM, Robert Hamilton wrote: Thanks, Kermit; Same error: It cannot locate GetRunTime() _______________________________________________ Ibm-netrexx mailing list [hidden email] |
OK; with lot's of help, I got the NetREXX/JAVA thing to work :
class StreamGobbler extends Thread is=InputStream type=String method StreamGobbler(is2=InputStream, type2=String) is = is2 type = type2 method run() public do br = BufferedReader(InputStreamReader(is)) line=String null line = br.readLine loop while line \= null System.out.println(type ">" line) line = br.readLine -- add write tries; -- I need to write the data from br.readline == line(?) to a line in file named 'C:\\dirsaved.'Date() -- but don't know where to start. end catch ioe=IOException ioe.printStackTrace() end
_______________________________________________ Ibm-netrexx mailing list [hidden email] |
When you are fluent in 'classic Rexx', but 'not in Java', and you do not want to look at a Java book describing all the details of I/O in Java: May I again suggest you download Rexx2Nrx and use the RexxFile routines for a starter? Those are documented in detail in www.Rexx2Nrx.com/RunTime. This might save you a lot of unsuccessful tries, as it simply implements linein, lineout, charin, charout in the way you are accustomed to .... Just a hint. Thomas Schneider. ============================================================= Am 08.11.2010 23:54, schrieb Robert Hamilton: OK; with lot's of help, I got the NetREXX/JAVA thing to work : --
Thomas Schneider Projects ReyC & LOGOS on www.KENAI.com _______________________________________________ Ibm-netrexx mailing list [hidden email]
Tom. (ths@db-123.com)
|
In reply to this post by Robert L Hamilton
"StreamFiler" below is a replacement class for the StreamGobbler
that will write the command output into a file. Just pass the
filename when you create the StreamFiler object. You will need to
modify that "Date()" object a bit to use it in a filename (The
colons are not legal Windows filename characters.) For example:
outputFiler = StreamFiler(p.getInputStream(), 'C:\\dirsaved.'Rexx(Date().toString).changestr(':',' ')) -- any output? outputFiler.start() --------------------------------------------- StreamFiler class to write an output stream to a file -------------------------------------- class StreamFiler extends Thread is=InputStream filename=String method StreamFiler(is2=InputStream, outputfilename=String) -- constructor method is = is2 filename=outputfilename method run() public -- a method that runs when the Thread object is started do br = BufferedReader(InputStreamReader(is)) -- create an object to read an output stream outfile = BufferedWriter(FileWriter(filename)) -- create an object to write data to a file line=String null line = br.readLine -- read the first line loop while line \= null -- System.out.println(type ">" line) outfile.write(line,0,line.length) -- write input line to output file outfile.newLine -- advance file to next line line = br.readLine -- read a new input line end outfile.close -- close the file when done catch ioe=IOException -- intercept any io errors and print a trace ioe.printStackTrace() end ----------------------------------------------------------------------------------------------------------------------------------------------------------- On 11/8/2010 2:54 PM, Robert Hamilton wrote: OK; with lot's of help, I got the NetREXX/JAVA thing to work : _______________________________________________ Ibm-netrexx mailing list [hidden email] |
Free forum by Nabble | Edit this page |