aspose file tools
The moose likes Java in General and the fly likes problems with using Runtime.getRuntime().exec().... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "problems with using Runtime.getRuntime().exec()...." Watch "problems with using Runtime.getRuntime().exec()...." New topic
Author

problems with using Runtime.getRuntime().exec()....

vikram solanki
Greenhorn

Joined: Dec 07, 2010
Posts: 8
Hi everyone... i am new to coding and i am having a bit of problem trying to execute a particular command...
i am trying to use Runtime.getRuntime().exec() to execute an .exe in command prompt... As output i am supposed to get an image(svg) file which is saved in a given directory... the code i am using for this is as given below...


i am using dot.exe to create the svg file... the poblem now is the SVG file is created but the size of the file is 0KB... but if i debug the prog everything is allright and i am getting an output file of some KB... can someone tell me the problem here please...
And i am using Netbeans6.7.1...
thanks a lot...
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

Welcome to JavaRanch. Please UseCodeTags when you post source code (I added them to your post this time).

Try calling output.flush(); before you close the output stream (between lines 12 and 13). This will write the buffer to the file.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
vikram solanki
Greenhorn

Joined: Dec 07, 2010
Posts: 8
Thanks a lot... that soled my problem...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

When you call Runtime.getRuntime().exec(...) this does not block the current thread. This means that the newly created process and the JVM are running concurrently. The deleting of the file on line 15 will probably occur before the launched process has finished. Use process.waitFor() to prevent this, but not before reading this article.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: problems with using Runtime.getRuntime().exec()....
 
Similar Threads
Runtime.exec
Cant get the output of a class file through the following JSP
waitFor method of a process object not working
Inserting BLOB data
Response Ok, but message not delivered. (SMS)