Runtime.exec() command to open default pdf reader

Hello
I want to launch a pdf-file (from within the code) on the system default pdf-reader. Can I somehow retrieve the path to the default pdf-reader and use it like this:
String pdfReaderPath = retrievePDFreaderpath(); // ????
String filename = new String("E:\\Test.pdf");
String[ ] open = {pdfReaderPath , filename};
try {
Process proc = Runtime.getRuntime().exec(filename);
} catch (IOException e) {
e.printStackTrace();
Thank you!

I am new to java programming. I am trying to launch a pdf file from a share drive, but I am getting the following error.
C:\Misc Java>java PdfExec
java.io.IOException: CreateProcess: I:/Bass/FRMGEB01.2005 0204 Invoice.pdf erro
=193
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at PdfExec.main(PdfExec.java:24)
Following is my simple code.
import java.io.*;
public class PdfExec {
public static void main(String argv[]) {
try {
Process proc = Runtime.getRuntime().exec("//whmax/WHMAX-COMMON/Bass/FRMGEB01.2005 0204 Invoice.pdf");
catch (IOException e) {
e.printStackTrace();
Any help will be appreciated. Thx!

Similar Messages

  • How can I run Runtime.exec command in Java To invoke several other javas?

    Dear Friends:
    I met a problem when I want to use a Java program to run other java processes by Runtime.exec command,
    How can I run Runtime.exec command in Java To invoke several other java processes??
    see code below,
    I want to use HelloHappyCall to call both HappyHoliday.java and HellowWorld.java,
    [1]. main program,
    package abc;
    import java.util.*;
    import java.io.*;
    class HelloHappyCall
         public static void main(String[] args){
              try
                   Runtime.getRuntime().exec("java  -version");
                   Runtime.getRuntime().exec("cmd /c java  HelloWorld "); // here start will create a new process..
                   System.out.println("Never mind abt the bach file execution...");
              catch(Exception ex)
                   System.out.println("Exception occured: " + ex);
    } [2]. sub 1 program
    package abc;
    import java.util.*;
    import java.io.*;
    class HelloWorld
         public static void main(String[] args){
         System.out.println("Hellow World");
    } [3]. Sub 2 program:
    package abc;
    import java.util.*;
    import java.io.*;
    class HappyHoliday
         public static void main(String[] args){
         System.out.println("Happy Holiday!!");
    } When I run, I got following:
    Never mind abt the bach file execution...
    I cannot see both Java version and Hellow World print, what is wrong??
    I use eclipse3.2
    Thanks a lot..

    sunnymanman wrote:
    Thanks,
    But How can I see both programs printout
    "Happy Holiday"
    and
    "Hello World"
    ??First of all, you're not even calling the Happy Holiday one. If you want it to do something, you have to invoke it.
    And by the way, in your comments, you mention that in one case, a new process is created. Actually, new processes are created each time you call Runtime.exec.
    Anyway, if you want the output from the processes, you read it using getInputStream from the Process class. In fact, you really should read that stream anyway (read that URL I sent you to find out why).
    If you want to print that output to the screen, then do so as you'd print anything to the screen.
    in notepad HelloWorld.java, I can see it is opened,
    but in Java, not.I have no idea what you're saying here. It's not relevant whether a source code file is opened in Notepad, when running a program.

  • Making Preview (3.0.9) my default .pdf reader

    Somewhere along the way Adobe Reader (now 8.1.2) seems to have taken over as my default .pdf reader. I can't find any way to change this so far. Since Preview is much faster I would like to have it be my default reader again. can I do this?
    Thanks,
    -Joe

    Select any PDF file then press COMMAND-I to open the Get Info window. In the Open With section select Preview from the drop down menu then click on the Change All button.

  • Feedback from runtime.exec(command)

    Hi,
    I hope someone can point out the problem with the following. I have a method that is supposed to execute a shell command. The shell command would look something like the following:
    serctl add 351 password [email protected]
    However when this command is executed in a shell/command line a prompt is shown ("MySql password:")asking for a password. Once the user enters the password, the user is added. My code currently executes the first half of the command but gets stuck on the password prompt. My code stops by the line "before the loop" and never enters the inner loop. So obviously my code isn't working properly to say that if the response is a password prompt, to pass it the password variable.
    Any ideas?
    Many Thanks.
    void addUser(String username, String password, String email, String passwd, HttpServletResponse response) throws IOException {
       String[] command = {"serctl", "add", username, password, email};
       //String[] command = {"pstree"};
       Runtime runtime = Runtime.getRuntime();
       Process process = null;
       response.setContentType(CONTENT_TYPE);
       PrintWriter out = response.getWriter();
       String s = "something";
       try {
         process = runtime.exec(command);
         System.out.println("Process is: " + process);
         System.out.println("Command is: " + command);
         BufferedReader in =
         new BufferedReader(new InputStreamReader(process.getInputStream()));
         BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
         OutputStream stdout = process.getOutputStream();
         System.out.println("before the loop");
         s=in.readLine();
         System.out.println(s);
         System.out.println(s);
         System.out.println(in);
         System.out.println(stdout);
         //while((s=in.readLine())!= null)
         while((s=in.readLine()).equals("MySql password: "))
           //s = in.readLine();
           System.out.println(in.readLine());
           System.out.println(s);
           out.println(s);
           if (s.equals("MySql password:  ")) {
             System.out.println("Must be equal to MySql password;");
             //stdout.write(passwd.getBytes());
             //stdout.write(adminpassword);
             //stdout.flush();
             //break;
        System.out.println("after the loop");
         System.out.println("Here is the standard error of the command(if any):\n");
         while ((s = error.readLine()) != null){
           System.out.println(s);
         stdout.close();
         in.close();
         error.close();
         out.println(in);
         out.println("<html>");
         out.println("<body bgcolor=\"#FFFCCC\">");
         out.println("You have successfully added a new user.<br><br>");
         out.println("User " + username + " has been created ");
         out.println("</body></html>");
        catch (Exception e) {
              System.out.println("Uh oh! Error adding new user.");
              e.printStackTrace();
    }

    Just a random observation:
    Sometimes programs that prompt for passwords do it in a way that is impossible to redirect (or at least requires special trickery, such as creating a pseudo-TTY). E.g. in Unix this involves opening /dev/tty and using that instead of stdout & stdin. This is done to make sure there really is a person who knows the password sitting there in front of the teletype.
    I don't know if the "serctl" program does that. If stdout&stdin redirection does not appear to work then it is a possibility.
    A quick googling for "serctl" reveals:
    Commands labeled with (*) will prompt for a MySQL password.
    If the variable PW is set, the password will not be prompted.
    which might or might not be an easier way to deal with this particular program. If it indeed is the same "serctl" program.

  • Running jar in unix using runtime exec command

    Hi, i want to run a jar in unix with the runtime.exec() command,
    but i couldn't manage to do it
    Here is the code
    dene = new String[] {"command","pwd","java tr.com.meteksan.pdocs.pdf.html2pdf "+ f.getAbsolutePath() + " " + pdfPath};
              System.out.println("Creating PDF");
              FileOutputStream fos = new FileOutputStream(new File(pdfPath));
              Runtime rt = Runtime.getRuntime();
              for(int i = 0 ; i < dene.length ; i++)
                  System.out.println("komut = "+dene);
              Process proc = rt.exec(dene);
              // any error message?
              StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR"); // any output?
              StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT", fos); // kick them off
              errorGobbler.start();
              outputGobbler.start();
              // any error???
              int exitVal = proc.waitFor();
              System.out.println("ExitValue: " + exitVal);
              fos.flush();
              fos.close();
    when i run this program, the exit value of the process is 0
    can you tell me whats wrong?

    i changed the string to be executed to:
                             dene = new String[] {"sh","-c","java -classpath \"" + Sabit.PDF_TOOL_PATH
                                  + "avalon-framework-4.2.0.jar:" + "" + Sabit.PDF_TOOL_PATH
                                  + "batik-all-1.6.jar:" + Sabit.PDF_TOOL_PATH
                                  + "commons-io-1.1.jar:" + Sabit.PDF_TOOL_PATH
                                  + "commons-logging-1.0.4.jar:" + "" + Sabit.PDF_TOOL_PATH
                                  + "fop.jar:" + Sabit.PDF_TOOL_PATH + "serializer-2.7.0.jar:"
                                  + Sabit.PDF_TOOL_PATH + "Tidy.jar:" + Sabit.PDF_TOOL_PATH
                                  + "xalan-2.7.0.jar:" + "" + Sabit.PDF_TOOL_PATH
                                  + "xercesImpl-2.7.1.jar:" + Sabit.PDF_TOOL_PATH
                                  + "xml-apis-1.3.02.jar:" + Sabit.PDF_TOOL_PATH
                                  + "xmlgraphics-commons-1.0.jar:" + "" + Sabit.PDF_TOOL_PATH
                                  + "html2pdf.jar:\" tr.com.meteksan.pdocs.pdf.html2pdf "
                                  + f.getAbsolutePath() + " " + pdfPath};     
    and it works now ;)
    thanks...

  • How can I change the default pdf reader from the installed (but not yet registered) Adobe Acrobat 9 Pro to Adobe Reader XI?

    How can I change the default pdf reader from the installed (but not yet registered) Adobe Acrobat 9 Pro to Adobe Reader XI? I'm having some hiccups getting Adobe to register the software, but since I set it as the default .pdf reader during setup, things try (and fail) to open in the as yet unregistered software. How can I change it temporariiy to the Acrobat Reader XI that I have installed?

    Anubha,
    It worked! Thank you so much.
    I'd opened file with the 'Open with' feature then clicking Adobe Reader,
    but that didn't do it. When I used 'Open with', then 'Choose default
    program...', it worked like a charm.
    Again, thank you!
    Jonathan
    On Wed, Mar 18, 2015 at 10:16 PM, Anubha Goel <[email protected]>

  • Can't set Skim as default pdf reader

    I recently updated from Snow Leopard to Mountain Lion. I needed to download a pdf from a government site but when using my default pdf reader, Skim, I got an error message saying I needed to use Adobe, so I switched my default to Adobe Reader.  When I was finished I tried to switch my default back to Skim  by going into get info on a pdf file and setting it to Skim, then open all with this app.  When I clicked out of the application field after choosing Skim the field kept popping back to Adobe.  I was able to change the default to Preview without a problem, but I can't get Skim to stick.  I can still open files with Skim by choosing "open with", but they revert back to Adobe or Preview icons when I close them.  Skim does not become their default.  Any suggestions on why this is happening and if it can be fixed? 

    Link,
    I can't even get that far.  When I have the "info" screen open and click on Skim in the drop down list, the entry reverts back to the previous default (Preview or Adobe).  I can choose a bunch of inappropriate apps, like Safari  or Kindle, and those will stay in the open with box, but Skim disappears.  Weird.
    Kathy

  • Acrobat Pro as Default PDF Reader

    How can I make Acrobat Pro my default PDF reader, I am using a Mac and whenever I open a pdf it opens it in the Mac OS's 'Preview' software instead of Acrobat Pro

    Select any PDF, Ctrl + click on "Mac", and select Adobe Reader under "Open With" option. Once the PDF opens with Reader, you will see an option to set it as default application to open PDF.

  • Making Adobe as the default PDf reader

    How can I make Adobe as a default pdf reader for windows phone 8?
    Where does the Adobe reader store local files in wp8? Can I know its path in windows phone 8?

    Maybe starting Acrobat 9 (NOT Distiller 9: this is an extra component
    of Acrobat, and not involved in opening PDFs) will help. But overall,
    mixing releases and Acrobat/Reader on the same computer isn't
    recommended for this sort of reason.
    Aandi Inston

  • Default PDF reader

    Hello
    I have an N97 Mini, bought SIM free. I use it as a mobile office.
    Two problems:
    I have installed a freeware PDF reader,and the trial version of Adobe Acrobat (now expired) came with the phone (I think - it may have installed when I bought a license for Quickoffice). I have set the freeware PDF reader as the default (Settings>Phone>Application Settings>Default apps.>Options>Advanced Options>) but it resets back to the trial Adobe app. I want the Freeware PDF reader to stick as the default reader.
    Also, I'd like to remove the Adobe Acrobat trial, but I can't find a way todo this.
    Suggestions, please!
    Thanks.

    You can't remove any of the 'trial' stuff it's embedded 
    As for default pdf reader, the only workarround I know is to save a pdf file, then open the pdf reader and select file from there !
    Good Luck
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • How do I specify Adobe Reader X as my default PDF reader in FireFox 4.0

    I have been using Nuance PDF Reader 6 as the PDF plug-in in FireFox, bus since installing FireFox 4, I have experienced issues with the Nuance reader. For example, when displaying a PDF file, the elevator does not work. If I can capture the URL of the PDF, I can open IE8, which defaults to Adobe Reader X as its PDF reader, but I cannot always capture the URL. I would like to switch to the Adobe Reader as my default PDF reader in FireFox 4.

    Well, you'd be wrong. Help->About tells me I am using FireFox 4.0. I do not see where I can get the name/version/serial of the PDF reader when I open it in Firefox. At least that's the case with the Nuance reader. Not sure about Adobe Reader X. Oh, and the Nuance reader can be VERY finicky about where you click on the elevator--particularly if the document has a lot of pages, which makes the elevator really tiny. I think some programmer didn't do his homework on how to apply the elevator code.

  • Every time I have have Preview as my default pdf reader. I download a pdf file, i get a dark grey screen. Any suggestions?

    I have Preview as my default pdf reader. Every time I download a pdf file, I get a dark grey screen. Any suggestions?

    Hi,
    I also installed Adobe Reader because an ebook I downloaded wouldn't open without it.
    I then chose Adobe Reader as my default. When I later uninstalled it using the Trash Me app-which usually clears everything out-I couldn't get Preview back as the default.
    I went to the "Library/Internet plug-ins" path and trashed the two Adobe Reader plug ins that were there. I used Secure Empty Trash, and then shut down completely and did not check the box to reopen any windows. Then I restarted the Mac.
    I not only shut down Safari, I closed all applications and shut down the Mac completely being sure to uncheck the "relaunch with windows open" button. When I turned the Mac back on, I opened Safari and went to an online PDF that I had been trying to open previously to test the app. It opened this PDF using Preview and showed it in Safari.
    I then tested using a PDF from my files and it opened in Preview.
    Quit Safari.
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type of copy / paste:   /Library/Internet Plug-Ins
    Click Go then move the Adobe PDF Browser plugin from the Internet Plug-Ins folder to the Trash.
    Relaunch Safari to test.

  • How set default pdf reader to goodreader

    how can I set default pdf reader to goodreader
    I'm new to the iPad
    thanks

    You can't. Safari will open downloaded PDF's from the web by default, form there you can tap on "Open In" to transfer the PDF to Goodreader or iBooks if you choose to.

  • How do you change the "default" pdf reader from acrobat back to preview?

    how do you change the default pdf reader from acrobat back to preview?

    In the Finder, select your pdf then click file get Info window. Select the Preview application from the open with menu and then click change all.

  • How do I make Preview the default PDF reader on Safari?

    I reinstalled Adobe and somehow it has become the default PDF reader for Safari. I prefer to use Preview, but I can't figure out how to set it back to Preview.

    ... a 5-10 minute job. 
    in order to change the default PDF viewer in Safari from Adobee, you need to have root user access!
    a bit tedious but really a easy task - see below:
    How to enable the root user:
    OS X Mavericks
    From the Apple menu choose System Preferences....
    From the View menu choose Users & Groups.
    Click the lock and authenticate as an administrator account.
    Click Login Options....
    Click the "Edit..." or "Join..." button at the bottom right.
    Click the "Open Directory Utility..." button.
    Click the lock in the Directory Utility window.
    Enter an administrator account name and password, then click OK.
    Choose Enable Root User from the Edit menu.
    come up with a password you wish to use in both the Password and Verify fields, then click OK. (you don't have to remember it forever)
    then, log out as yourself and log back in as the root user...
    at the login screen, the username will be root, and the password will be the one just made up in Step 10 above.
    don't set up with icloud or anything - just cancel any popups that ask for keychain or whatever...just get to the desktop screen and then, from the menu bar at the top of the desktop screen...choose the Go menu....now hold down the option key and another choice on the menu (for the library) should show up...
    choose library. 
    in the search bar at the top right of the finder window for the library folder, type kind:plugin.... the two plugins should show up.   be sure the search is searching the library folder.
    after you have trashed the two adobe pdfviewer plugins, empty the trash and log out as the root user ...
    now, disable root user:
    to disable the root user
    OS X Lion and Mavericks
    From the Apple menu choose System Preferences....
    From the View menu choose Users & Groups.
    Click on the lock and authenticate with an administrator account.
    Click Login Options....
    Click the "Edit..." or "Join..." button at the bottom right
    Click the "Open Directory Utility..." button.
    Click the lock in the Directory Utility window.
    Enter an administrator account name and password, then click OK.
    Choose Disable Root User from the Edit menu.
    ...sorry this explanation is a bit slapdash... hope you've had success... hit me off with a point if it helps!

Maybe you are looking for

  • How do I have multiple versions of the same .chm?

    Our developers recently were required to make changes to an earlier version of our software (thank goodness for backups). So I'm having to revert to that earlier version, make changes, and create a revised .chm. HOWEVER, I already had completed the u

  • No common sense in iOS 7

    I can't say how dispppointed I am with iOS 7. The UI is so obviously flawed in design, I just can't believed it went through with any one at Apple having the common sense of stopping this. There are ensledd issues : - The sliders that now answer to a

  • IBook superdrive won't play DVD it burned

    We have a new iBook w/ a superdrive. We used it to burn a DVD with no problems except the iBook won't play it. The DVD will play in home DVD players and other Macs that we have tried but not in the iBook that authored the DVD (w/ iDVD). The DVD will

  • Full database impdp

    Hi, When i am trying to import data using datapump i am facing the below error. OS : AIX 5 Oracle Version : Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Command used fro EXPORT:' expdp admin/XXXXs DIRECTORY=DATA_PUMP_DIR dumpfile

  • Is there "Interface Type Node" present in WD JAVA as in WD ABAP ?

    Hi, Experts, As i have gone through WD ABAP in that i found  "Interface Type Node"  under Context tab  but i have a dought is that type "Interface Type Node" is present in WD JAVA or not.If not why and its use ? Thank You, Shabeer Ahmed.