Results 1 to 5 of 5
- 03-25-2010, 05:31 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
running external program in directory different from working dir
Hi,
My java code calls an external program. This program produces a file that is created in the working directory where my java code was called from.
I call the external program like this:
Runtime r = Runtime.getRuntime();
Process p = r.exec("C:/my_program.exe");
p.destroy();
This is what I want: my external program needs to be executed in a subdirectory of my current working directory.
Apparently, if I add the following before I call the external program
System.setProperty(user.dir,"C:/subdir/);
it has no effect on the location of the file created by the external program.
Any suggestions, ideas?
thanks in advance,
Nick
- 03-25-2010, 05:42 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Use java to move the file once it's been created?
- 03-25-2010, 05:46 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
That's not an option I think. Here is why:
I am using multi-threading to start multiple external programs at once. Since they all produce files with the same filename, they need to be executed in different directories. otherwise I would have files with equal filenames.
Note that I have no possibility to set the filename as an argument of the external program.
- 03-25-2010, 05:53 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Ah, OK.
A quick peek at the API and I see that exec() has a version that'll take a working directory.
- 03-26-2010, 08:16 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Problem with running an external program via java
By g123456 in forum New To JavaReplies: 4Last Post: 12-30-2009, 05:06 PM -
working directory in web application
By Juuno in forum Advanced JavaReplies: 1Last Post: 05-04-2009, 07:45 PM -
Static function to get current working directory
By Java Tip in forum Java TipReplies: 1Last Post: 06-23-2008, 02:13 AM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
How to get the current working directory in EJB?
By sathish_2111 in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-19-2007, 04:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks