lei feng

Greenhorn
+ Follow
since Aug 23, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by lei feng

I get a old jar-file running in a jvm and a new jar-file in another folder.I think the old is locked by the jvm. but i can use copy cmd to copy the new file and overwrite this old file.(copy cmd/ctrl+c,ctrl+v). but i can not use cut/paste to finish it(move cmd/ctrl+x,ctrl+v). it will get a error window. if i stop the jvm. i can use the the cut/paste to overwrite the old file. so i'm wondering whether the old file running in jvm is locked.
In java, the situtation is same.I use File.renametoFile() i can not overwrite the old-file.But i use some code to copy it, i can overwrite the old file.
So I'm pulzzed,i don't know how to explain it.

this is the copy code i used.

16 years ago
I get it the answer.
see the different result:

use this code, the process will wait until you stop it manually


this code will stop after the cmd finsh task.

the reason: use getRuntime.exec() will get a inpustream,if you don't read this inputstream in time. the process will lock. if you use waitFor() the whole process will lock,so you must read(clear) the inputstream to esure the process run.
16 years ago
thanks you reply.I still want to figure out how it works to ensure when the proccess wait until the cmd finish. if i use move xxx xxx this cmd i don't get any message. but i try to use the dir cmd, i get the whole information from the cmd to the eclipse console...I'm going to check the code
16 years ago
1. if i only use process.waitFor(), the whole program will wait forever and never wake up and return.
2. but using this code the program only wait for the file have been moved. then run the next code? i don't know why?
3. the StreamGobbler as a thread. what is its function? i suppose this thread is why the waitFor() can return..but i don't know how does it get it?

who can answer me....thanks any help will be appreciate!
16 years ago
16 years ago
Hey guys i get the method to open another window(or explore) by using cmd "start"
String startCmd="cmd /k start D:\\";
p2=Runtime.getRuntime().exec(startCmd);
try it...it can also anyother window.....
but you'd better not write the "process.destory()"
[ August 28, 2007: Message edited by: lei feng ]
16 years ago
i found a method but i think this is not the best way to open the cmd window. that is using the .bat file. with .bat file in java program it can pop-up the cmd window...
16 years ago

Originally posted by Roger F. Gay:
Environment variables are things like path and classpath, that are set for the whole system. You can view or edit them through the Advanced tab in Systems on the Control Panel - which you bring up by clicking start and selecting Control Panel (in Windows). Control-Panel->System->Advanced-tab->Environment-variables-button

I don't understand how starting a Java program brings up a cmd window if you don't know how to bring up a cmd window from a Java program? How does doTest.test (.class?) bring up a cmd window?



that means i get two programs(p1,p2) to invoke each other. at first p1 run and when the condition is right p1 invoke the p2 before quit.but in this action, the p2 is running in background you can see the "cmd.exe,java.exe" in process explore but can not get another cmd window. and when some condtions is right p2 also invoke the p1 before quit. the situtation is the same as before. but i need the cmd window to see some System.out.print information. because our main program(whatever p1,p2) print the information to the cmd window. So i need cmd window......
16 years ago

Originally posted by Roger F. Gay:
I may be trying to do the same thing this week. It would be nice to get a response before then. This is another new thing for me. I have code to start a second application from the first, but haven't tried to start a command window for it.

I have little experience - but perhaps this will help. I think that the arguments might need to be in a String array.

Use a second argument if you need to set environmnet variables.

[ August 28, 2007: Message edited by: Roger F. Gay ]



i don't understand what is the "environmnet variables"?
i've try it but i also can not get a cmd window.......so if i use exec to run a java program, i can not get the console information......so the point.....so i must get a cmd window by using runTime.exec("java -cp test doTest.test")
16 years ago

Originally posted by manishkumarlal cs:
whats the different between
String s = "abc";
and
String s = new String("abc");



String is a very special class in JAVA.
String s=new String("abc"): jvm create a String Object contained "abc" then return a refrence pointed to s. SO s a refrence not a real object.
String s = "abc": jvm first use String.equals to find whether there is a same object in "string pool". if it get it, it will return this refrence pointed to s.if not, it will create a object in "string pool" and return the refrence. so you can try a experiment like this;
String s1 = new String("abc");
String s2 = new String("abc");
use "==" to see whether they are equal. and use "String.equal()" to see whether they are equal.
hope it will help you!
16 years ago
sometimes if you want to cast int to String, you must use the wrapper class integer to get it. for example
int i=5;
String s=Integer.toString(5);
or inverse cast:
String s="5";
int i=Integer.parseInt(s);
i always use the integer in casting type.....
you also can cast int to Integer or inverse.
int i=5;
Integer in=new Integer(i);
inverse cast
Integer in=new Integer(5);
int i=in.intValue();
generally data passing must be using Class.......and int/long/double is not a Class....
[ August 28, 2007: Message edited by: lei feng ]
16 years ago
for example:I use Runtime.getRuntime().exec("cmd /k dir"); the result is it run in the background. but i want to it show me the cmd window. how to do that? any help will be appreciated.
16 years ago
sorry i make a mistake. I just change the command like this
String moveCommand="cmd /k move /y D:\\app1.class D:\\test\\doUpdate&exit";
after finish the task exit the process, not controled by the external
16 years ago
you can remove "public" key words
16 years ago
sorry i think i get it by using waitFor(). i think i forgot to clear and rebuilder the project.thank all.....
16 years ago