Running curl command from a java program using Runtime.getRuntime.exec

for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
Any ideas on why this might be happening?

thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
I am using 7.15 in my system.
Below is the code which errors out.
public int execCurlCmd(String command)
          String s = null;
          try {
              // run the Unix "ps -ef" command
                 Process p = Runtime.getRuntime().exec(command);
                 BufferedReader stdInput = new BufferedReader(new
                      InputStreamReader(p.getInputStream()));
                 BufferedReader stdError = new BufferedReader(new
                      InputStreamReader(p.getErrorStream()));
                 // read the output from the command
                 System.out.println("Here is the standard output of the command:\n");
                 while ((s = stdInput.readLine()) != null) {
                     System.out.println(s);
                 // read any errors from the attempted command
                 System.out.println("Here is the standard error of the command (if any):\n");
                 while ((s = stdError.readLine()) != null) {
                     System.out.println(s);
                 return(0);
             catch (IOException e) {
                 System.out.println("exception happened - here's what I know: ");
                 e.printStackTrace();
                 return(-1);
     }

Similar Messages

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Is there any way to run without using Runtime.getRuntime().exec()

    I am looking for a way to get my program to fun files on my system without using
    Runtime.getRuntime().exec() because it's causing me nothing but problems, is there any other way to do it without using this command?

    Can't think of an easier way (JNI, etc.).
    If you have not read the following article you really should, it might clear up a lot of your problems with exec():
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to use Runtime.getRuntime().exec() in JSP? is it works in JSP or not

    Hi to all,
    i want run a .exe file from JSP file. In java i am able do this, using Runtime.getRuntime().exec().
    but same thing, when i trying with JSP it is not working?
    plz let me is there any other ways to do it..

    It depends, usually (ie in an J2EE container) you're not allowed to access files or the runtime environment, by definition. What do you wan't to achieve with the exe?
    --olaf                                                                                                                                                                                                                                                                                                                                                           

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • Execute several UNIX OS commands from inside Java program

    Greetings,
    I would like to be able to execute from a Java program several of the following UNIX commands
    script filename
    cd
    date
    grep
    diff
    I have been able to get a single command to work with
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("dir");
    My goal here is to accomplish a Java program which will use JDBC to access an Oracle database with SQL and then compare the resultant flat file with a diff command in Unix to another delimited file from an Excel spreadsheet. Your input is appreciated.
    Thank you

    I would suggeat to use JDBC to get the data from database and then read your file and then use existing java diff program from following link to find the differences between the files
    http://www.bmsi.com/java/
    I hope this helps
    VAN

  • How can I pass system commands from a java program? Urgent!

    hi,
    I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
    If u have any idea, or have any information about the kind os application reply back.
    Thanks
    Deepa Datar

    This is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
    import java.io.*;
    public class cmddemo2
    public static void main(String arg[])
    try
    System.out.println("cmd");
    Process p=Runtime.getRuntime().exec("cmd.exe");
    DataInputStream din=new DataInputStream(p.getInputStream());
    DataOutputStream dout=new DataOutputStream(p.getOutputStream());
    System.out.println("after streams");
    String s;
    dout.writeChars("type cmddemo2.java");
    while((s=din.readLine())!="\n")
    System.out.println(s);
    dout.writeChars("dir");
    String s1;
    while((s1=din.readLine())!="\n")
    System.out.println(s1);
    System.out.println("over");
    catch(Exception e)
    { System.out.println("Exception : "+e);

  • Using Runtime.getRuntime().exec(DOS Program) with Windows 2000.

    I am trying to spawn a DOS Program from within Java.
    On Win95/98/ME, I use
    Process     p = Runtime.getRuntime().exec("START /w command.com con /c myDOSProgram.exe");
    This works on these platforms. On Win 2000, I use
    Process     p = Runtime.getRuntime().exec("START /w cmd.exe con /c myDOSProgram.exe");
    It does not work at all.
    I have tried all combinations of using START, cmd.exe, con /c, etc.
    I can spawn a Windows App using
    Process     p = Runtime.getRuntime().exec("windows.exe");
    And it works fine.
    What does it take to spawn a DOS program from Java on the Windows 2000 op sys?

    Hi. I recently wrote a java GUI that calls a DOS program with mixed success. Here's the code I used to make the call:String osName = System.getProperty("os.name" );
    String[] cmd = new String[4];
    if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
         cmd[0] = "cmd.exe";
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
         cmd[0] = "command.com" ;
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else
         System.out.println(osName);
    Process proc = runtime.exec(cmd);Check out this article, it gives a good explanation of how to use the exec() call:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Hope this helps!

  • How to execute an application in Solaris using Runtime.getRuntime.exec() ?

    I am currently doing a project which requires the execution of Solaris applications through the use of Java Servlet with this Runtime method - Runtime.getRuntime.exec()
    This means that if the client PC tries to access the servlet in the server PC, an application is supposed to be executed and launched on the server PC itself. Actually, the servlet part is not an issue as the main problem is the executing of applications in different platforms which is a big headache.
    When I tried running this program on a Windows 2000 machine, it works perfectly fine. However, when I tried it on a Solaris machine, nothing happens. And I mean nothing... no errors, no nothing. I really don't know what's wrong.
    Here's the code.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
              Process process;                                                       Runtime runtime = Runtime.getRuntime();
              String com= "sh /opt/home/acrobat/";
              String program = request.getParameter("program");
              try
                        process = runtime.exec(com);
              catch (Exception e)
                   out.println(e);
    It works under Windows when com = "c:\winnt\system32\notepad.exe"
    When under Solaris, I have tried everything possible. For example, the launching of the application acrobat.
    com = "/opt/home/acrobat"
    com = "sh /opt/home/acrobat"I have also tried reading in the process and then printing it out. It doesn't work either. It only works when excuting commands like 'ls'
    BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));Why is it such a breeze to execute prgrams under Windows while there are so many problems under Solaris.
    Can some experts please please PLEASE point out the errors and give me some advice and help to make this program work under Solaris! Please... I really need to do this!!
    My email address - [email protected]
    I appreciate it.
    By the way, I'm coding and compiling in a Windows 2000 machine before ftp'ing the .class file to the Solaris server machine to run.

    it is possible that you are trying to run a program that is going to display a window on an X server, but you have not specified a display. You specifiy a display by setting the DISPLAY environment variable eg.
    setenv DISPLAY 10.0.0.1:0
    To check that runtime.exec is working you should try to run a program that does not reqire access to an X Server. Try something like
    cmd = "sh -c 'ls -l > ~/testlist.lst'";
    alternatively try this
    cmd = "sh -c 'export DISPLAY=127.0.0.1:0;xterm '"
    you will also need to permit access to the X server using the xhost + command

  • Opening a new browser using Runtime.getRuntime().exec(cmd); under windows

    Can Runtime.getRuntime().exec(cmd); open a URL in to a new browser in wondows OS or ...can we force it to any specific browser insted on OS's default browser...
    It does open a new bowser under MAC but not under windows..
    cmd = "'rundll32 url.dll,FileProtocolHandler"+URL (windows)
    Thanks

    public class WindowsProcess
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[3];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "start";
              Process process = Runtime.getRuntime().exec( cmd );
              process = Runtime.getRuntime().exec( cmd );
    }When you run the above code you should get two open dos windows.
    Now just just enter some html filename and hit enter in each window. IE should start up separately in each window.
    Thats also what should happen if you specify the html file as the fourth parameter. A new process should be created and two separate windows should open with a browser in each.

  • Unable to run curl command from process c#

    Below is the curl command i am trying to run from c# script and i failed to execute please help
    curl -K config.cfg
    http://10.10.10.10:8080/MyApp/task
    string curlDirectory = "E:\\application";
    string curlArg1 = " -K ";
    string curlArg2 = "config.cfg";
    string curlArg3 = " http://10.10.10.10:8080/MyApp/task";
    Process process = new Process();
    process.StartInfo.FileName = "cmd.exe";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.RedirectStandardError = true;
    process.Start();
    StreamWriter sw = process.StandardInput;
    sw.WriteLine("cd " + curlDirectory);
    sw.WriteLine("curl " + curlArg1 + curlArg2 + curlArg3);
    sw.WriteLine("exit");
    sw.Close();
    C:>cd E:\application\
    E:\application>curl -K config.cfg
    http://10.10.10.10:8080/MyApp/task
    E:\application>exit

    Did you get any error? can you remove the below line and try:
    process.StartInfo.CreateNoWindow = true;
    Fouad Roumieh

  • Calling an unix command from a java program which runs on windows

    Hello All
    I have an Java Application which is run on windows server (I)
    I have another Sun Server (II)
    I want to call an unix command on server(II) from java application which is on server(I)
    I am using Samba Server in order to share files between Windows Server and Unix Server
    Can I use samba in order to call command
    or is there any way to open an telnet session within java application
    I will be grateful if you give me some suggestion on this issue
    Regards
    BEKIR BALCIK
    J2EE Application Developer
    Argela Technologies ...

    cross post
    http://forum.java.sun.com/thread.jspa?threadID=624601&messageID=3553626#3553626

  • If i run program via Runtime.getRuntime().exec, UrlConnection doesn't work.

    I have two pograms.
    One GUI which allow us directly runs server application and display output.
    Two server application which operates with http.
    Under Windows XP operation system everything works fine. If i run server application via comand like " java -jar **** " , everything works fine. But if i run server application via GUI under Win2000, server application doesn't work. Application freeze if try to get output stream from Url connection.
    Can you help me please?
    url = new URL("http://neco");
    connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("POST");
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setAllowUserInteraction(true);
    connection.setReadTimeout(10);
    connection.setUseCaches(false);
    // Right There !!!
    output = new DataOutputStream(connection.getOutputStream());

    It is probably because the getOutputStream() or getErrorStream() of Process is blocked waiting for you to read from those streams.
    See http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.htmlIn short read from getOutputStream() from its own thread and also read from getErrorStream in another thread. If you are using 1.5 you can use ProcessBuilder and combine the OutputStream and ErrorStream into one stream and then you just need one thread. For you information, in 1.5 Runtime.exec() just call through to ProcessBuilder.

  • Spawn a java process using runtime.exec() method

    Hi,
    This is my first post in this forum. I have a small problem. I am trying to spawn a java process using Runtime.getRuntime().exec() method in Solaris. However, there is no result in this check the follwoing program.
    /* Program Starts here */
    import java.io.*;
    public class Test {
    public static void main(String args[]) {
    String cmd[] = {"java", "-version"};
    Runtime runtime = Runtime.getRuntime();
    try{
    Process proc = runtime.exec(cmd);
    }catch(Exception ioException){
    ioException.printStackTrace();
    /* Program ends here */
    There is neither any exception nor any result.
    The result I am expecting is it should print the following:
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    Please help me out in this regard
    Thanks in advance
    Chotu.

    Yes your right. It is proc.getInputStream() or proc.getErrorStream(). That is what I get for trying to use my memory instead of looking it up. Though hopefully the OP would have seen the return type of the other methods and figured it out.

Maybe you are looking for

  • Satellite P775-100 3D: Problem with first initialization of the 3D function

    Hi, I have a problem with my new Toshiba Satellite Notebook P775-100 3D. Wenn I start the 3D wizard for the first 3D using, then disappears the mouse coursor from screen. The mouse works but is not visible. Sometimes by trying can to find the button

  • Unable to transfer iTunes Library to external Harddrive

    I followed the online directions and tried to transfer my iTunes library to my external hard drive, but it wont do it and I get the message "required file is in use".  Does anyone have any suggestions?

  • SIGSEGV 11 segmentation violation - sp3 upgrade

    I get the following error while upgrading WL 6.1 from SP2 to SP3.... I noticed someone else on this newsgroup got the same error while upgrading to SP2. Any clues on where/ why this occurs? thanks _nik ============================ bash-2.03$ java -cp

  • RMI gcInterval - Does it invoke a Full GC?

    My query is with regard to the bug reported here: [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6200091] The Bug description suggests that if the rmi gc interval is left at its default value of 1 minute (for JDK 1.5) it causes a Full Garbage Co

  • Blacklining plugin in Indesign CS5 issue

       Hi, My company recently upgraded their workstations to Windows 7 with Adobe CS5 standard and acrobat X. Now we installed Blacklining from http://www.blacklining.com/. My problem lies on the vertical line (sidebar) that the Acrobat distiller is pro