Runtime.exec("ftp") , but cann't read from Process.getInputStream()

first, Runtime.exec("ftp")
then I read from Process.getInputStream()
but I get nohting. why ?
I think I should read a prompt string "ftp>"
and, Process.getInputStream() return a BufferedInputStream, how can I get a non-buffered InputStream from it ?

Disregarding your actual question, I'll take a stab at the REAL issue.
If you're going to script an FTP session, why not use ftp -s:<filename>?

Similar Messages

  • Problem while Reading from process.getInputStream

    I hav created asimple java IDE . To compile the file i have created a thread which further calls Process.start(). for compilation and Afr that for running.
    After it, i read from outputstream of process and whatever i get, i paste on a box for user to see.
    For normal(I mean in some hello world type program) my ide compiles and shows the correct output .
    But in othercase it doesnt shows the output. Though neither it generates any error.
    I m really confused.
    Plz if u getting my problem , try o solve.
    Thanx a lot

    it doesnt help .
    I m still stuck. i need helpYour problem is in line 42. You need to change it to -

  • Runtime.exec("Perl Script writing and reading on I/O"), handling Streams

    Hi all !!
    In a first place : sorry for my english if it's not really understandable but I try to do as good as possible !
    I'm writing a GUI with Swing that will allow (in one of my multiple tables) the user to run a Perl Script.
    This Perl Script ask the user to choose a Folder ... then read all the files in this folder and for each file (xml File), extract the datas and put them in a database. But when a file that has to be inserted in the database contains this line : <Template_Used name="ST1.mtt"> and if the Template table in my database doesn't have the "ST1.mtt" stored ... the Perl Script ask to the user to give him the path of the file "ST1.mtt" so that the script can put the "ST1.mtt template" datas in the database.
    This script runs well when it is from a windows console.
    But I need a graphic interface !!!
    So I created a JButton "Process a folder".
    When the button is pressed, a JFileChooser appears and ask the user which Folder has to be processed.
    Then a Process is created with the command : ("cmd.exe /C \"C:\\Program Files\\Fluke\\Ansur\\ProcessFolder.bat\").
    The BatFile :
    {code}cd C:\Documents and Settings\tsd\Desktop\Gael-Project\Project_Files
    perl Process.pl
    exit{code}
    At this moment everything is working well.
    But my Process.pl (which is 300 lines long ... and that you don't even want to hear about), ask in a first time the Path of the folder to process and sometimes ask the path to a file (a template file).
    So I need to read and wirte on the STDIN/STDOUT during the exec of the Process.
    In order to handle this I created two different threads : one reading the Process.getInputStream with a BufferedReader and one other writing on the Process.getOutputStream with a PrintWrinter.
    What I need to do is :
    When I read a line from the InputStream saying "I need the path of the ST1.mtt file", I should run a JFileChooser ... the user find the file in the computer ... and I write in the OutputStream the path of the file, so that my Perl Script doesn't have un Unitialised value on <STDIN> and can continue to process !!
    I'm pretty sure it's possible ... because at the moment I just used a trick :
    When the user push the "process a folder" button, I write the paths in the OutputStream before than the script needs it and it works !
    But I need to write in the OutputStream only when it is time !!!
    Any idea ??
    Here are some parts of my code :
    {code}
    String filename = File.separator+"tmp";
              JFileChooser fc = new JFileChooser(new File(filename));
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
              // Show open dialog; this method does not return until the dialog is closed
         fc.showOpenDialog(null);
         Folder = fc.getSelectedFile();
              new GoodExec(cmd);
    {code}
    {code}
    public class GoodExec {
         public static Process proc;
         public static StreamGobbler errorGobbler;
         public static StreamGobbler inputGobbler;
         public static StreamGobbler outputGobbler;
         public GoodExec(String cmd)
         try
                   Runtime rt = Runtime.getRuntime();
              proc = rt.exec(cmd);
         // any error message?
         errorGobbler = new
         StreamGobbler(proc.getErrorStream(), "ERROR");
         // any input?
         inputGobbler = new
         StreamGobbler(proc.getInputStream(), "INPUT");
         // any output?
              outputGobbler = new
              StreamGobbler(proc.getOutputStream(), "OUTPUT");
         // kick them off
         errorGobbler.start();
         inputGobbler.start();
         outputGobbler.start();
         // any error???
         int exitVal = proc.waitFor();
         System.out.println("ExitValue: " + exitVal);
         } catch (Throwable t)
         t.printStackTrace();
    {code}
    {code}
    public class StreamGobbler implements Runnable
    InputStream is;
    OutputStream os;
    String type;
    Thread thread;
    public static String chaine;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.os=null;
    this.type = type;
    StreamGobbler(OutputStream os, String type)
    this.os = os;
    this.is=null;
    this.type = type;
    public void start () {
         thread = new Thread(this);
         thread.start ();
    public void run()
    try
    if (is == null){
         PrintWriter toProgram = new PrintWriter(os);
         File FolderToProcess = ProcessFolder.Folder;
    String Folder = FolderToProcess.getPath();
    toProgram.write(Folder);
    toProgram.close();
    else {
         if (os == null){
         InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    String comp = "Please enter the exact path of the directory that contains the files you want to process.";
    while ( (line = br.readLine()) != null){
         if (type.equals("INPUT")){
              chaine+=line+"\n";
         if (line.equals(comp)) {
              System.out.println("give directory");RUN A JFILECHOOSER AND GIVE THE DIRECTORY TO THE OUTPUTSTREAM
    System.out.println(type + ">" + line);
    is.close ();
    catch (IOException ioe){
         ioe.printStackTrace();
    {code}
    And here is an example of a simple perl script that could be used (it s a simple one !!) :
    {code}
    #!/usr/bin/perl -w
    use strict;
    print "Please enter the exact path of the directory that contains the files you want to process.\n";
    my $dir= <STDIN>;
    chomp ($dir);
    print "titallala $dir";
    if (the template of the file is not in the database){
    print "Please give me the template so that I can put it in the database";
    $dir= <STDIN>;
    chomp ($dir);
    {code}
    Thank you for your help ... if it's possible to help me !!
    Gael

    BalusC -- The line that gives me my NullPointerException is when I call the "DisplayProduct()" method. Its a dumb question, but with NetBeans how do I find out which reference could be null? I'm not very familiar with how NetBeans works with finding out how to debug. Any help you can give me would be greatly appreciated.The IDE is com-plete-ly irrelevant. It's all about the source code.
    Do you understand anyway when and why a NullPointerException is been thrown? It is a subclass of RuntimeException and those kind of exceptions are very trival and generally indicate an design/logic/thinking fault in your code.
    SomeObject someObject = null; // The someObject reference is null.
    someObject.doSomething(); // Invoking a reference which is null would throw NPE.

  • Unicode - again! 不 is showing up as 上, but only if read from a file!

    Hi, LabVIEWers:
    If you've been following some of my posts here (I have no idea why you would, but just in case), you know that a project I am working on is a translation of things from English to unicode.  It's been working fabulous so far, except for one thing.
    It seems that 不 is consistently showing up as 上 in any text box, caption, etc, etc, but only if I read it from a text file!  It doesn't matter what position it's in, and I tried saving it in notepad (unicode option), notepad ++ (encode in UCS-2 little-endian) and Word (other encoding - Unicode) but it doesn't make a difference.  And when I copy the wrong character and paste it, it really IS the wrong character, like it magically got transformed.
    If I paste the right character into a any kind of text box, it works fine.  Furthermore, I can wire that text box to anything that accepts a string and it shows up correctly there, too.
    Here's ther weird thing:
    As far as I can tell, that's the only character I am having trouble with!!!
    Anyone have any ideas?
    Thanks!
    Oops, LV 2009 SP1.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
    Solved!
    Go to Solution.

    Dec 10 is linefeed and dec 13 is carriage return. Are you sure you disabled Convert EOL on the read file function? I'm not sure how you read in the Unicode strings but if you use Read Text File there is a right popup option to have LabVIEW do some automatic translation. Does Read File deal with Unicode or are you doing something yourself there? Either it does not and then of course does ASCI replacement or if it does the code for Convert EOL does not correctly treat Unicode characters.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Repeatedly Changing AXI BAR 0 Address Register but Microblaze Keeps Reading from the Same Address

    Hello,
    I work on a project based on AXI PCIe Bridge.
    What I am trying to do is access a userspace memory block directly from a Microblaze (or DMA).
    So far, I use posix_memalign() to allocate a block of memory in the userspace which has the size of the page (4K).
    Once I allocate this block of memory I fill it with data.
    Then I pass its pointer to my kernel driver where I use get_user_pages() and a few other functions to create a scatter/gather list in order to get the physical addresses of my userspace pages (so far I get one physical address since I have allocated one page).
    The next step is to write that physical address to the AXI BAR 0 address register.
    I validate that the correct address is written at this register.
    Then I ask the Microblaze to read the data from this physical address but I get different data.
    After reading the data I ask the Microblaze to write new ones at this address.
    I repeat all that procedure by allocating new memory block filled with different data in my userspace.
    Then I pass the new physical address again at the AXI BAR 0 address register.
    This time the Microblaze reads the last data it wrote itself.
    It seems like the Microblaze always reads/writes from/to an unknown address even if I repeatedly give different physical address at the AXI BAR 0 address register.
    Are there any suggestions?
    Could this be a cache coherency issue?
    Trying the "cache coherency issue" approach, though, did not solve the problem either.
    I have, also, tried a different case which worked.
    I used pci_alloc_consistent() in my kernel driver and I gave its physical address to the AXI BAR 0 address register.
    Then the MIcroblaze writes and reads data from/to this block of memory correctly.
    The kernel driver verified that the transfers are correct since it read the same data that the Microblaze previously wrote.
    This approach always worked for every new allocated block of memory.
     

    Hello,
    I work on a project based on AXI PCIe Bridge.
    What I am trying to do is access a userspace memory block directly from a Microblaze (or DMA).
    So far, I use posix_memalign() to allocate a block of memory in the userspace which has the size of the page (4K).
    Once I allocate this block of memory I fill it with data.
    Then I pass its pointer to my kernel driver where I use get_user_pages() and a few other functions to create a scatter/gather list in order to get the physical addresses of my userspace pages (so far I get one physical address since I have allocated one page).
    The next step is to write that physical address to the AXI BAR 0 address register.
    I validate that the correct address is written at this register.
    Then I ask the Microblaze to read the data from this physical address but I get different data.
    After reading the data I ask the Microblaze to write new ones at this address.
    I repeat all that procedure by allocating new memory block filled with different data in my userspace.
    Then I pass the new physical address again at the AXI BAR 0 address register.
    This time the Microblaze reads the last data it wrote itself.
    It seems like the Microblaze always reads/writes from/to an unknown address even if I repeatedly give different physical address at the AXI BAR 0 address register.
    Are there any suggestions?
    Could this be a cache coherency issue?
    Trying the "cache coherency issue" approach, though, did not solve the problem either.
    I have, also, tried a different case which worked.
    I used pci_alloc_consistent() in my kernel driver and I gave its physical address to the AXI BAR 0 address register.
    Then the MIcroblaze writes and reads data from/to this block of memory correctly.
    The kernel driver verified that the transfers are correct since it read the same data that the Microblaze previously wrote.
    This approach always worked for every new allocated block of memory.
     

  • Windows x64: install went fine but will not read from write to any ipod

    Quicktimes 7.0.4 and the latest version of Itunes is installed and everything has worked fine other than I can not add any music to any of the three ipods that i have at my house(Pretty Big Freakin Problem). I have read previous posts and understand that apple posted that itunes does not support x64, but does anyone have any idea if there will ever be a supported version? Or should I just sell or get rid of my ipods? The apple post doesn't even say if they are going to work on this upgrade. Any help in solving this issue or letting me know if this is just a dead end, would be greatly appreciated.

    In the PSE 12 folder, double click on the Setup.exe
    If you get this, just click on Ignore

  • DVD drive will play audio CDs but will not read from a DVD with photos saved on it -

    DVD drive will not read DVD with photos saved on it. Also will not run system discs. Gives mesage "please insert a disc into Drive D. It plays CDs fine so appears to be working.
    Please advise - thank you.
    Gerry

    I too have this same problem.  Posted about it in another thread then saw this.  I hope there is a fix.

  • Executing a runtime.exec statement from an ejb

    Hi all,
    relativly new to j2ee. I need to use the runtime.exec command to uncompress a set of files from an ejb.
    So far, ive tried that and even the most basic commands like
    /usr/bin/ll *
    and i don't get any response back other than: exit value = 2
    when executing:
    Runtime runtime = Runtime.getRuntime();
    // Process proc = runtime.exec("/usr/bin/uncompress "+this.localFileStore+"*.Z");
    Process proc = runtime.exec("/usr/bin/ll * ");
    // put a BufferedReader on the ls output
    InputStream inputstream = proc.getInputStream();
    InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
    BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
    // read the ls output
    String line;
    while ((line = bufferedreader.readLine()) != null) {
    System.out.println(line);
    // check for ls failure
    try {
    if (proc.waitFor() != 0) {
    System.err.println("exit value = " + proc.exitValue());
    catch (InterruptedException e) {
    System.err.println(e);
    No output from the buffered reader. Any one have any ideas as to why i cannot execute any runtime commands? This is also related to the thread i created where i'm looking for a java library for uncompressing a unix compressed file (unix compress = *.z and not zip or gz files). I think my only two options are to either use the runtime to uncompress these files or.. use some java library to uncompress these files. Let me know if anyone can offer any hints/helpfull comments/libs
    Thanks a bunch

    I might be wrong on this one, but I believe using Runtime.exec() would generally be frowned upon when invoked from an EJB. The reason? EJB implies a remote call. Can you guarantee that a given native process or service will be available on all possible remote nodes that the EJB might be deployed on? Maybe. Can it actually be achieved? Yes. Is it in the spirit of EJB? Probably not.
    - Saish

  • Make can't recursively call Make when run from Runtime.exec (for some user)

    This one is a little complicated. The afflicted platform is Mac OS X. It works fine on Linux, it seems, and even then, it does work for some Mac OS X users...
    First, the setup. I have a Java program that has to call GNU Make. Then, GNU Make will recursively call Make in some subdirectories. This results in the following Java code:
    String make = "make"; //on windows, I have this swapped with "mingw32-make"
    String workDir = ...; //this is programmatically detected to be the same folder that the parent Makefile is in
    Runtime.getRuntime().exec(make,null,workDir);This calls make on a Makefile which has the following line early on to be executed (this is only a snippet from the makefile):
    cd subdirectory && $(MAKE)When I fetch the output from the make command, I usually get what I expect: It cd's to the directory and it recursively calls make and everything goes smoothly.
    However, for one particular user, using Mac OS X, he has reported the following output:
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky. I've gotten other suggestions that it may be some strange setup with the env variables (My Mac developer is implementing a fix/workaround for 'environ', which is apparently posix standard, but Mac (Mr. Posix Compliance...) doesn't implement it. When he finishes that, I'll know whether it worked or not, but I get the feeling it won't fix this problem, since it's intended for another area of code entirely...
    Also worth mentioning, when the user calls "make" from the terminal in said directory, it recurses fine, getting past that particular line. (Later on down the road he hits errors with environ, which is what my aforementioned Mac dev is working on). Although calling "make" by hand is not an ideal solution here.
    Anyways, I'm looking for someone who's fairly knowledgeable with Runtime.exec() to suggest some way to work around this, or at least to find out that perhaps one of the User's settings are wonked up and they can just fix it and have this working... that'd be great too.
    -IsmAvatar

    YoungWinston
    YoungWinston wrote:
    IsmAvatar wrote:
    However, for one particular user, using Mac OS X, he has reported the following output:One particular user, or all users on Mac OS?In this case, I have two mac users. One is reporting that all works fine. The other is reporting this problem.
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.If that is being reported on the command line, then I'd say that make wasn't being found at all.If make isn't being found, then who's interpreting the Makefile?
    It's also just possible that the make script on Mac isn't correctly exporting its PATH variable, though it seems unlikely, since this would surely have been reported as a bug long ago.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky...Also seems unlikely. 'cd' has been around since shortly after the K-T extinction event.
    WinstonBy "acting wonky", I mean being given a bad work directory or some such, such that it's not changing to the intended directory.
    Andrew Thompson
    Andrew Thompson wrote:
    (shudder) Read and implement all the recommendations of "When Runtime.exec() won't" (http://www.javaworld.com/jw-12-2000/jw-1229-traps.html).
    Already read it. I already know the dreadful wonders of Runtime.exec. But in this case, it's been working fine for us up until one Mac user reported that make can't find make.
    Also, why are you still coding for Java 1.4? If you are not, use a ProcessBuilder, which takes a small part of the pain out of dealing with processes.Usually I do use a ProcessBuilder. I noticed that it usually delegates to Runtime.exec() anyways, and seeing as I didn't need any of the additional functionality, I decided to just use Runtime.exec() in this particular case.
    jschell
    jschell wrote:
    So print thos env vars, in your app and when the user does it.I'll look into that. It's a good start.
    -IsmAvatar

  • Runtime.exec() and batch files

    I am having a problem on Windows 2000 while trying to execute a batch file with the Runtime.exec() method. Basically, the exit value returned from the call to Runtime.exec(), returned specifically by the waitFor() method in the Process class, is always zero, even if the batch file fails miserably. After looking into batch files further, it seems to me that the only way to get the exit value of the commands run in the batch file back to the Runtime.exec() call is to put "EXIT %ERRORLEVEL%" in the batch file. What this actually does is exit the command(cmd) shell that the batch file was running in with the exit code of the last command run. This is all great when calling the batch file with a Runtime.exec() call, but when you run it in a cmd window, the window closes when the batch file completes, because the call to EXIT exits the entire shell. I guess i'm just wondering, am i correct in assuming the exit value returned to the java process is going to be the exit value of the shell in which the batch file is running? I need to have the exit value actually indicate whether the batch file ran successfully or not, and if i have to put in the EXIT %ERRORLEVE% (which exits the cmd shell with the exit value of the last command run), then i'll do that, but if someone knows a better way of doing this, i am all ears. Thanks in advance

    To run any command from java code, the method is
    Runtime.getRuntime().exec( myCommandString )
    Where, myCommandString is something like "/full/pathname/command".
    If the pathname contains spaces (specifically in Windows), e.g. "c:\program files\windows\notepad", then enclose it in quotes within the quoted string. Or pre-tokenize them into elements of an array and call exec(String[] cmd) instead of exec(String cmd).
    From JDK1.3 there are two new overloaded Runtime.exec() methods. These allow you to specify starting directory for the child process.
    Note, there is a gotcha associated with reading output from commands. When the runtime exec's the process, it passes to it 3 streams, for stdin, stdout, and stderr; the out and err are buffered but the buffer size isn't very big. When your process runs, it reads (if needed) from in, and writes to out and err.
    If it doesn't write more than the buffer-size, it can run to completion.
    But if it tries to write more data to one or the other stream than the buffer can hold, the write blocks, and your process hangs, waiting for you to empty the buffer so it can write some more.
    So after the exec call, get the streams, and read from them in a loop until they both hit end-of-stream (don't block on either one, just read whatever is available from each, each loop iteration).
    Then when the streams have ended, call the process.waitFor() method to let it finish dying.
    Now, here is a code snippet how you achieve this.
    String strCommand = "cmd.exe /c " + strCommand;
    // For Solaris / unix it will be
    // String strCommand = "/usr/cobra/sol/runInstaller.sh";
    boolean bWait = true;
    //execute the command
    try
         Runtime r = Runtime.getRuntime();
         Process pr = r.exec(strCommand);
         Process pr = r.exec(callAndArgs);
         BufferedInputStream bis =new BufferedInputStream(pr.getInputStream ());
         int c=0;
         /** Outlet for IO for the process **/
         while (c!=-1)
              c=bis.read();
         /**Now wait for the process to get finished **/
         if(bWait == true)
              pr.waitFor();
              pr.destroy();
    catch(Exception e)
         System.out.println("Could not execute process " + strCommand);
         return(false);

  • Runtime.exec() on shell script - unix

    Hello all.
    I'm gonna run a shell script and its parameter on unix solaris.
    This is the whole command:
    -> ex.sh "03/02/03 11:22:00"
    'ex.sh' consists of the line like this.
    -> ex date="$SSCREATE"
    So, I expect "03/02/03 11:22:00" would be replaced with '$SSCREATE'
    BTW, in Java class I invoke the shell in this way.
    Process p = Runtime.getRuntime().exec("./ex.sh \"03/02/03 11:22:00\"");
    InputStreamReader in = new InputStreamReader(p.getInputStream());
    BufferedReader br = new BufferedReader(in);
    But I can't get any output from this, I mean, when I use
    'br.readLine()'
    Why is that? Do I miss something?
    Thanks in advance.

    Thanks Jason.
    Actually, I succeeded to run only 'whatever.sh'.(without any parameters) - No problems using Runtime.exec().
    But, according what you wrote, is '/usr/bin/sh' a must as a prefix before real commnad line?
    And what if the argumet has "(double quote) at the both ends?
    I'd be glad if you show me the example.
    Thank you again.

  • Runtime.Exec for 'appref.ms' files

    Hello!
    I am using Runtime.exec to call an external application from java classes. These classes are in turn used by JSP.
    The external application is an "Application Reference" type application in Windows, and has the extension appref.ms
    From Glassfish logs, I can see the following error:
    java.io.IOException: Cannot run program ""C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms"": CreateProcess error=193, %1 is not a valid Win32 application
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
        at java.lang.Runtime.exec(Runtime.java:593)
        at java.lang.Runtime.exec(Runtime.java:466)
        at list.CreateNew.runExternal(CreateNew.java:251)
        at list.CreateNew.CreateQuotationDR(CreateNew.java:222)
        at list.CreateNew.processRequest(CreateNew.java:88)
        at list.CreateNew.doPost(CreateNew.java:143)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
        at java.lang.ProcessImpl.start(ProcessImpl.java:30)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
        ... 35 moreWhen I open a command window and type
    "C:\Documents and Settings\Administrator\Start Menu\Programs\MyCompany\QuotEncrypt.appref-ms" <arg1> <arg2>
    The program runs without problems.
    I actually tried copying the QuotEncrypt.exe file that is built in the development environment to the server and give that as argument to Runtime.exec, but in that case the application seems to run (I use waitfor and the return value from waitfor) , return with 0, but it has no side effects. It does not even write to its log file.
    Hence I am at a loss to what to do.
    Appreciate any help,
    Irem

    And now the program hangs.
    It seems to be time for code indeed:
    String[] commands = {"C:\\WINDOWS\\system32\\cmd.exe", " /start ", Constants.QuotEncryptPath, " \""+qfile + "\"", Constants.encryptPassword};
      runExternal(commands);
          public static void runExternal(String commands[])
            try
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing ");
                String whole="";
                for(int i =0; i < commands.length ; i ++)
                whole = whole + commands;
    System.out.println(whole);
    Process proc = rt.exec(commands);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
    import java.io.*;
    import java.util.*;
    * @author iaktug
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    @Override public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    I got the code from the famous when Runtime.exec() won't. I am now suspecting there is something wrong with this part.
    Essentially I want a very simple thing. The external program will run and the parent program will wait for it and get the return value.
    I added the Stream stuff simply to prevent deadlock/hanging.
    I am considering trying to get that out completely.
    The server messages go as follows:....
    Execing |#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878233;_ThreadName=httpSSLWorkerThread-8082-4;|
    C:\WINDOWS\system32\cmd.exe /start "C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms" "H:\QUOTATIONS\Quotations\In Progress\q00502.xls"1q2w3e|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>Microsoft Windows [Version 5.2.3790]|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>(C) Copyright 1985-2003 Microsoft Corp.|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>|#]

  • Increasing memory used by java process when calling Runtime.exec()

    Hi everyone!
    I'm running a servlet Oracle iAS 9i, Jserv. It receives an image posted by a user and does a System.exec() which performs a call to convert (an image processing utility included in ImageMagick).
    After a few hours, java process start taking more and more RAM, until it crashes with an error like this:
    Memory: 5394008 free of 134217728 total. (I log this myself)
    Exception: java.io.IOException: Not enough space
    java.lang.UNIXProcess.forkAndExec(), line -2.
    java.lang.UNIXProcess.<init>(), line 54.
    java.lang.Runtime.execInternal(), line -2.
    java.lang.Runtime.exec(), line 553.
    ImageProcessor.convert(), line 235.
    ImageProcessor.createItemPics(), line 124.
    Uploader.doPost(), line 69.
    As you can see, this is not an OutOfMemoryError, but something else in connection with O/S.
    This is not related to hard disk space, since there is a lot of free space in every filesystems
    After restarting the webserver, everything goes back to normal and start increasing RAM again.
    Is there anything I can do? Any help will be gratly appreciated... Thanks!!!
    Dani.-

    Have you had any solutions to this pal?
    I am also suffering. I tried closing the processes by:
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec("/opt/sta_rpms.sh " + sFileName);
    proc.waitFor();
    proc.getInputStream().close();
    proc.getOutputStream().close();
    proc.getErrorStream().close();
    proc.destroy();
    proc = null;
    but still after like a day...Though our codes are not alike, it sounds like the same reason.
    Cheers!

  • Why couldn't I use Runtime.exec(cmd)?

    I try to use Runtime.exec(cmd) but I can't do it. Could you give me a sample that use Runtime.exe(cmd).
    Please help me!

    import java.io.*;
    class RuntimeExec{
         private static boolean quit;
         public static void main(String[]args)throws IOException{
              if(args.length<1){
                   System.out.println("Type in program to run");
                   System.exit(1);
              quit = false;
              Runtime run = Runtime.getRuntime();
              Process newProcess = run.exec(args[0]);
              if(newProcess!=null){
                   BufferedReader br = new BufferedReader(new InputStreamReader(newProcess.getInputStream()));
                   PrintWriter os = new PrintWriter(newProcess.getOutputStream());
                   BufferedReader be = new BufferedReader(new InputStreamReader(newProcess.getErrorStream()));
                   if(br!=null)(new ReadThread(br)).start();
                   if(os!=null)(new WriteThread(os)).start();
                   if(be!=null)(new ErrorThread(be)).start();
                   try{
                        newProcess.waitFor();
                        newProcess.destroy();
                        quit = true;
                   }catch(InterruptedException ie){}
              }else
                   System.out.println("Error creating process");
              System.out.println("Done!");
              System.exit(0);     
         private static class ReadThread extends Thread{
              private BufferedReader is;
              public ReadThread(BufferedReader is){
                   this.is = is;
              public void run(){
                   String s;
                   while(!quit){
                        try{
                             s=is.readLine();
                             if(s!=null)
                             System.out.println(s);
                        }catch(IOException e){}
         private static class WriteThread extends Thread{
              private PrintWriter br;
              private BufferedReader ss;
              public WriteThread(PrintWriter br){
                   this.br = br;
                   ss = new BufferedReader(new InputStreamReader(System.in));
              public void run(){
                   String s;
                   while(!quit){
                        try{
                             s=ss.readLine();
                             if(s!=null)
                             br.println(s);
                        }catch(IOException e){}
         private static class ErrorThread extends Thread{
              private BufferedReader br;
              public ErrorThread(BufferedReader br){
                   this.br = br;
              public void run(){
                   while(!quit){
                        String s;
                        try{
                             s=br.readLine();
                             if(s!=null)
                             System.err.println(s);
                        }catch(IOException e){}
    Sorry about that stupid code, here is code that works... with deadlocks maybe??

  • Runtime exec MFC console program

    I'm trying to launch an MFC console program with some parameters
    but it doesn't work
    no exeception (but it looks like it has never been launched)
    I made a program which is not MFC that works in the same configuration
    But I need to launch an MFC one
    could some one help me??

    I found the solution
    it works with jdk 1.3 (3 parameters)
    when you launch the exe you must specify
    the working path
    runtime.exec("path/exename",null,"workingDirectoryPath");

Maybe you are looking for