Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

How to define a Windows directory in ProcessBuilder directory() method?

Thread view: 
minjie@excite.com - 16 Mar 2006 19:43 GMT
I'm very new to Java, so please excuse me if the quesions are too
trivial.

I want to invoke a process with the following:
------
       ProcessBuilder pb = new ProcessBuilder("crw32.exe",
"myreport.rpt");
       pb.directory("C:\Program Files\Crystal Decisions\Crystal
Reports 9\"); // <-- error
       Process p = pb.start();
------
But I got the error "Illegal escape character". If I change that
statement to:
       pb.directory("C:\\Program Files\\Crystal Decisions\\Crystal
Reports 9\\");

I got the error:
"cannot find symbol.
symbol  : method directory(java.lang.String)".

Isn't directory() a method in ProcessBuilder class (I'm using Java
1.5)? Is the error due to the fact that I still don't have the correct
path defined in there? How should I define that directory? Is it OK if
there are spaces in the path?

Also, how do I define the directory for the file "myreport.rpt" as
"C:\My Reports\", if I've already defined a directory to be "C:\Program
Files\Crystal Decisions\Crystal Reports 9" for the command "crw32.exe"?

Thanks.
Jean-Francois Briere - 16 Mar 2006 22:42 GMT
> Isn't directory() a method in ProcessBuilder class...

The correct statement is:
pb.directory(new File("C:\\Program Files\\Crystal Decisions\\Crystal
Reports 9"));

> Also, how do I define the directory for the file "myreport.rpt"...

Depends of what you want to achieve.
Must your program be executed where the 'myreport.rpt' is located?
If so then you should have 'C:\My Reports' as working directory and do:

ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Crystal
Decisions\\CrystalReports 9\\crw32.exe", "myreport.rpt");
pb.directory("C:\\My Reports");

Or maybe you want your program be executed in the software folder.
If that case you should have 'C:\Program Files\Crystal
Decisions\Crystal Reports 9' as working directory and do:

ProcessBuilder pb = new ProcessBuilder("crw32.exe", "C:\\My
Reports\\myreport.rpt");
pb.directory("C:\\Program Files\\Crystal Decisions\\CrystalReports 9");

Regards
minjie@excite.com - 16 Mar 2006 23:50 GMT
> > Isn't directory() a method in ProcessBuilder class...
>
[quoted text clipped - 21 lines]
>
> Regards

Hello Jean-Francois, thank you very much! pb.directory(new File("..."))
worked! I tried both methods in your examples. They both worked. I
guess for my application, I'll use your first example (i.e., use C:\My
Reports as working dir).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.