Getting output from a process

hi friends and gurus!
can somebody give me actuall working code to get the
output from a process let's say Process p=Runtime.exec("cmd c/ dir c:"); in windows,
and stores the output in a textfile let's say out.txt.
please give me the java code and not hints!
any effort to help me will be highly appreciated.
Thanx in advance!
sparya.

import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;
class read{
public static void main(String[] args){
String data=""
  try{
   BufferedReader reader=new BufferedReader(new FileReader(new File(args[0])));
   while((data=reader.readLine())!=null){
    System.out.println(data);
  catch(FileNotFoundException fnfe){
   System.out.println("cant find file "+args[0]);
  catch(IOException ioe){
   System.out.println("cant read file "+args[0]);
}to use type java read filename (including path if you need it)
hint, type java read read.java (cool, its nearly a palindrome)

Similar Messages

  • Get output from dos window to jtextarea/textarea

    hi
    i am executing the following lines of code:
    1)Runtime r=Runtime.getRuntime();
    Process p=r.exec("javac <filename.java>");
    when executing this there is no exception fired but i am not being able
    to get the output from the ods console to a textarea
    or for that matter i donot get any output anywhere
    2)if i change it to
    Process p=r.exec("java <filename");
    similar thing happens i.e no output
    can anyone plz help
    thanx.

    Sorry, this < was the wong way around
    Process p=r.exec("java filename >test.txt")
    Then read in data from test.txt, something like this should do it :))   public String getTextFile(String text) throws Exception{
          int reader = 0;
          text = "";
          FileReader in = new FileReader("test.txt");
             do {
                reader = in.read();
                text += (char)reader;
             }  while (reader != -1);
          in.close();
          return text;

  • Error Getting Output From ICloudTask

    I went through the Azure Batch Tutorial for .NET and am having issues with getting the output from the ICloudTask. After waiting for the tasks to complete I have the coded below:
    foreach (ICloudTask task in listjob.ListTasks())
    string taskFileContent = task.GetTaskFile(Constants.StandardOutFileName).ReadAsString();
    Console.WriteLine("Task " + task.Name + " says:\n" + taskFileContent);
    It throws a System.AggregateException on task.GetTaskFile with an inner exception of:
    {"The remote server returned an error: (404) Not Found."}
    I did some research but haven't been able to determine why I am getting this error?

    I see in the sample that the second use of TaskStateMonitor (TSM) does not check for timeout...  We will add this and you might want too as well.  
    If the TSM times out you might want to confirm the pool has VMs and that they reach TVMState.Idle (i.e.: are available to run tasks).
    You do not mention the exact task state you see but it is possible for a task to be in the TaskState.Completed state and still not have a stdout.txt file.
    You could list the files with ICloudTask.ListTaskFiles(recursive: true) to see what files are actually there.
    Also you can check the exit code (ICloudTask.TaskExecutionInformation.ExitCode) and/or the the TaskSchedulingError (ICloudTask.TaskExecutionInformation.SchedulingErrro) to see if the task ran correctly.
    daryl
    ps: don't forget to ToString() the inner BatchException.  I posted to the forum earlier on this and there are data in the exception that can tell you more than "not found"... 

  • Not getting outputs from JavaScript Patch in QC2

    The JavaScript Patch no longer generates outputs from outputs[n]. The outputting of data just stopped.
    An example output generator (no other instructions in the JavaScript patch):
    outputs[0] = "string";
    was sent to an Image With String patch and then to a Billboard patch (the only existing patches). No text appeared in the viewer. When in Editor, the cursor placed over Output #0 shows only:
    Type Virtual
    with no value. The input string into Image With String shows "".
    When disconnecting the JavaScript patch from the Image With String patch and I entered "help", the text help appeared in the viewer.
    I reinstalled Quartz Composer and there was no change. Anyone have any idea what is going on?

    What I've learned: the Tascam 122L has known issues when working with Leopard. Back in the store, I plugged another external card (Presonus Audiobox USB), which immediately worked with the Mac as though they were friends since birth.
    I am rapidly warming to Mainstage.

  • Getting output from a C programme

    Hi
    I am trying to execute a C programme (.o file) on Solaris and get its output .
    The C programme is a simple function which returns 0 or more then zero after executing some logic .
    I tried to use Runtime.exec() method but was not able to get any out put from the function , where as I did same in a perl script and was able to get the output .
    I have even tried to get error stream , input stream but I always get -1 as a return value .
    Following is my program
    Runtime rt = Runtime.getRuntime();
    String[] arg =new String[]{"program","arg1","arg2"};
    Process p =rt.exec(arg);
    BufferedInputStream buf = new     BufferedInputStream(p.getErrorStream());
    int data=buf.read();
    System.out.println("date is "+data);
    BufferedInputStream buf1 = new     BufferedInputStream(p.getInputStream());
         while((data=buf1.read())!= -1)
              System.out.println("data input is "+data);
    arg1 and arg2 are 2 arguments that the program needs . It always returns a value with might be 0 or non zero.
    I know I can try to use JNI , but i beleive using Process is a simple solution (if it works)
    Thanks

    .o files are usually no executables but object files. They need to be linked (with an object including the main funtion) to yield an executable.
    Shared objects are usually called *.so.

  • Rippling waves in DVD output from rendering process? Has anyone seen this?

    I have created a new project within Premiere Pro CS3. I have imported in about 300 still photos to create a DVD slide show mixed with some movie footage from one avi file. The following are the specs of the stills:
    1. Each still was scaled down to 1440X960 in size within Photoshop CS3. None of the images were scaled up.
    2. I disabled Premiere from resizing the images during import process so that I can setup panning and zooming each image.
    3. I added all images to my timeline with a 6 second delay.
    4. I then setup all even images to start at %size of 50% and then zoom out to 100% using keyframes.
    5. I then setup all odd images to start panning from left to right, during the 6 seconds they are displayed, with the image %size of 75%
    I then added music to the audio track and then exported as a Movie, which created an avi file.
    I then imported this avi file into Encore and created my final DVD, which is only about 30 minutes long.
    I gave a copy to a friend, and when he attempted to view the movie on his MAC and then his PC running XP, he reported that he was seeing rippling waves throughout the video. He explained them to look kind of like heat waves that you would see coming off hot asphalt. Which this cause the image to be somewhat distorted. When he placed the DVD in his home TV dvd system and it displayed on his TV, the results were much better, but you can still see a little of those waves. I also see a little of those waves on my new dvd player attached to my High Def TV.
    My questions tho this group are:
    1. What causes these waves to appear?
    2. How to get rid of them and make the video more high resolution looking?
    Thank you all for your help.
    Rick

    > What causes these waves to appear
    Interlacing.
    > 2. How to get rid of them and make the video more high resolution looking?
    Use progressive frames for computer playback. Or set up your PC's DVD software to deinterlace DVDs on playback (quality may vary).
    You can also apply the "anti-flicker" settings in Premiere's motion to soften it a bit.

  • Getting output from an OS command from an ABAP program

    Hi Folks!
    I have a requirement, is it possible to call an operating system command, and also get its output back to the ABAP program that has called it?
    For example, from an ABAP program calling the "dir" command from Windows and getting back (as a string) the directory listing to the ABAP program?
    Thanx in advance!
    Juan.

    This is will help you
    << Moderator message - links removed >>
    Please do not post a list of links. This simply encourages laziness. The OP could have found these with a little work.
    Edited by: Rob Burbank on Dec 13, 2010 9:19 AM

  • Giving input to running EXE & getting output from it

    Hi there,
    I want to invoke an EXE file using runtime.exec() & also want to give some input to it when it's in running state & also want to trace the output of that EXE.
    I tried it using PipedStream but failed to do this,
    please suggest something.
    Thanks In Advance,
    parag

    Here is my code.......
    //Pipe Writer class
    import java.io.*;
    public class Pipe_Writer extends Thread {
         PipedWriter pWriter = new PipedWriter();
         public Pipe_Writer() {}
         public PipedWriter getPipedWriter() {
              return pWriter;
         public void run() {
              Process p = null;
              try {
                   p = Runtime.getRuntime().exec("cmd");
              } catch (IOException e) {
                   e.printStackTrace();
              BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
              BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
              BufferedReader reader2 = new BufferedReader(new InputStreamReader(System.in));
              String line;
              String rd = "";          
              try {
                   rd = reader2.readLine();
                   System.out.println(rd);               
              } catch (IOException e1) {
                   e1.printStackTrace();
              try {
                   // writer.write("dir\n"); //writing to process
                   writer.write(rd + "\n");
                   writer.flush();          
                   while ((line = reader.readLine()) != null) {
                             System.out.println(line);
                             pWriter.write(line);  //writing to pipe
              } catch (IOException e) {
                   e.printStackTrace();
    }// Pipe reader class
    public class Pipe_Reader extends Thread{
         PipedReader pReader;
         public Pipe_Reader(Pipe_Writer writer)throws IOException{
              pReader = new PipedReader(writer.getPipedWriter());
         public void run(){
              try {               
                   while(true){
                        System.out.println((char)pReader.read());  //Reading from pipe
              } catch (Exception e) {
                   e.printStackTrace();
    }// main method
    public static void main(String[] args)throws IOException {
              Pipe_Writer writer = new Pipe_Writer();
              Pipe_Reader reader = new Pipe_Reader(writer);
              writer.start();
              reader.start();
         }

  • Getting output from my MBP to LCD TV

    Read any postings in this forum but could not find an answer. I have Apple's mini displayport, a DVi to HDMI cable and the appropriate audio cables.
    After connecting the MBP to the LCD TV I can see the desktop on the TV**. However when I closed the lid the TV goes black. With the lid open I run front row and it work on the MBP screen and on the TV I only get the same desktop image**
    What am I doing wrong?
    ** By the way the desktop picture in my MBP doesn't show. What it shows on the TV is the apple desktop purple "galaxy" image. Interesting!

    eew and Network 23,
    Thanks for adding to my post. It is very clear now. One of the problems I had is that I didn't realize that in System Preference>Displays, the menu changes a bit if you have the monitor connected or not.
    Two more questions,
    1) Based on your suggestions I prefer the extended desktop mode to preserve higher output resolution. I guess that when you have Mirroring off, it automatically means that you have the Extended Desktop option on, right?
    2) I cannot get the whole thing to work when I close my MBP. The TV goes black. I have an external mouse and keyboard (both bluetooh). I played with the "Arrangement" setting but nothing. What am I doing wrong.
    Thanks in advance.

  • Input and output from child process

    Hi all,
    I am developing an IDE for the Haskell functional programming language. The application runs the Haskell interpreter as child process, and sends and receives input from the interpreter. At the moment I'm programming the integrated console through which the IDE should communicate with the interpreter. The problem is that when I send a command to the interpreter to execute the code I can't detect when the code is running and when it waits for input, so I'll be able to dissable and enable input in the the console respectivly. Please answer as soon as possible, and if my explanation of the problem is not clear enough please just comment about it. Thank you in advance.

    Generally the way I have seen that sort of things designed is like this: You have a script in mind. For example:
    1. Send command "ABC DEF" to the interpreter.
    2. Wait until it responds with "OK" or "Failed".
    3. If it responded with "Failed" then quit.
    4. Send command "XYZ XYZ" to the interpreter.
    5. ... and so on
    You can do this in simple or complicated ways, of course. But if you can't do it, then you're going to find it difficult to do anything at all. For example you won't know when the interpreter is waiting for input (that seems to be your problem already).

  • Getting output from StreamRedirectThread.java

    Hi,
    For the purpose of my work, I am trying to store the output that is produced by StreamRedirectThread.java into a vector as shown in the code below. When I try to print out that vector the output is not as the same as it is printed in the StreamRedirectThread.java program. For example if the output form the program prints out the numbers form 0 to 5, the vector output is doubled in size and prints:
    index = 0 content=0
    index = 1 content=
    index = 2 content=1
    index = 3 content=
    index = 4 content=2
    index = 5 content=
    index = 6 content=3
    index = 7 content=
    index = 8 content=4
    index = 9 content=
    index = 10 content=5
    index = 11 content=
    Can anybody advice me what to do about it. I tried but couldn't fix it. The code of StreamRedirectThread.java is as
    import java.io.*;*
    *import java.util.*;
    import com.sun.jdi.*;*
    *import com.sun.jdi.request.*;
    import com.sun.jdi.event.*;*
    *import com.sun.jdi.connect.*;
    class StreamRedirectThread extends Thread {
    private final Reader in;
    private final Writer out;
    private static Vector outvector = new Vector(0); // victor of objects that contains output result
    private static final int BUFFER_SIZE = 2048;
    * Set up.
    * @param name Name of the thread
    * @param in Stream to copy from
    * @param out Stream to copy to
    StreamRedirectThread(String name, InputStream in, OutputStream out) {
    super(name);
    this.in = new InputStreamReader(in);
    this.out = new OutputStreamWriter(out);
    setPriority(Thread.MAX_PRIORITY-1);
    public void run() {
    try {
    char[] cbuf = new char[BUFFER_SIZE];
    int count;
    while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) {
    //out.write(cbuf,0,count);
    String s = new String(cbuf,0,count);
    if (!(s.equals(null)))
    TemplateApp.vv.addElement(s);
    outvector.addElement(s); out.write(s);
    out.flush();
    } catch(IOException exc) {
    System.err.println("Child I/O Transfer - " + exc);
    public synchronized static Vector getOutVector()
    return outvector ;
    }Thanks a lot for help

    The problem was with endline stored in the vector. I did the follwing and it worked for me.
    String separator = System.getProperty("line.separator");
      while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) {
                 if ( count == 0 ) {
                    continue;
                 String s = new String(cbuf,0,count);
                 out.write(s);
                 out.flush();
                 s = s.replace(separator, "");
                 if (s.length() !=0 )
                            outvector.addElement(s);
           }

  • Get output from dos window to jtextarea

    the code is:
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("javac <filename>");
    i have used
    BufferedReder br=new BufferedReader(new InputStreamReader(p.getOutputStream));
    but on compilation it shows error
    plz someone help
    i need it urgently.

    Sorry, this < was the wong way around
    Process p=r.exec("java filename >test.txt")
    Then read in data from test.txt, something like this should do it :))   public String getTextFile(String text) throws Exception{
          int reader = 0;
          text = "";
          FileReader in = new FileReader("test.txt");
             do {
                reader = in.read();
                text += (char)reader;
             }  while (reader != -1);
          in.close();
          return text;

  • WaitFor() hangs if output from child process is bigger than few lines.

    I'm using j2sdk1.4.1_01.
    it seems like the bug which was reported many times, but supposed to be fixed in current version.
    any ideas, sugesstions?
    is there any way to change the size of the buffer?

    Coincidence? It should be 4096, actually - the size of the I/O buffer.
    Runtime.exec() gives you a handle to a process. You have to spawn a couple of threads to read the standard output and standard error of the process, or the process will hang after filling the output pipe, which is usually 4K.

  • Not getting output from pic-servo board

    Greetings everyone and thanks in advance. I wish to use a Pic-Servo SC controller  board (http://www.jrkerr.com/) to control a single stepper motor, using LabView. Here's what I've done so far:
    -I already have installed 32 and 64 bit LabView (2011) and tried the test program in both
    -VISA controller is properly installed
    -USB to Serial FT232R converter is also installed, and configured in 19200 baud rate
    -COM3 port is shown as the assigned port for the controller, and selected as such in LV
    So far, I have managed to get the test program to run without communication errors, but upon sending any commands to the motor, it is completely unresponsive and behaves like it has no current or controller attached, despite it being configured in the basic 1-motor setup specified by Jrkerr site.
    Any help, comment or suggestion about how I could manage to get the motor moving will be welcome.

    Van you attach the manual? I get an error every time I try. I'm not convinced that it is RS485 from the brief product description. It talks about buying a RS232-RS485 adapter to communicate to multiple controllers.

  • How can a page get data from orace process

    Hi all.
    i have a process out a cousor .
    how apex get the data of the cousor.
    report only can get view/table ?????

    944378 wrote:
    Hi all.Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "944378".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand
    i have a process out a cousor .
    how apex get the data of the cousor.
    report only can get view/table ?????"Cousor"? You mean "REF CURSOR"? (Note that there is a spellchecker available when posting to the forum: click the button marked with "ABC" and a tick.)
    APEX does not have native support for basing reports on REF CURSORs.
    See +{thread:id=2358877}+
    (Always search the forum before posting a question. 98% of questions have been asked and answered before.)

Maybe you are looking for

  • Unable to get the composite instance for the invocation. This could be because instance has not yet been created or because the audit level for the SOA infra has been set to Off

    I am on Oracle 11.1.1.7 BPM suite on W8 64 bit. I can't launch the flow trace and get the error "Unable to get the composite instance for the invocation. This could be because instance has not yet been created or because the audit level for the SOA i

  • Display on external monitor is pixelated

    I am at wit's end, so figured I'd check in with the brain trust. I have a SONY DHR1000 deck hooked up to the G5 via fire wire. The deck is hooked up to a regular TV monitor via standard RCA cable. I've changed the cables and have swapped my camera wi

  • Currency Conversion at Query Level

    Guys, Can some one tell me step by step procedure to do Currency conversion from USD to Mexican PESO at query level in BI 7.0. I have read lot of threads but not clear in maintaining the Exchange rates and also in creating the variables.  Thank you,

  • How to Play a sample sound using Java

    Hi, I have an mp3 music files in database. When a user chooses a particular button, all the songs are fetched from the database. I have two buttons namely, 'Buy' and 'Play Sample'. If I click the 'Play Sample' button, a sample of the song has to be p

  • Delete from dimension

    Hello All, I need to compare my dimesnion to the fact tables that use this dimension and delete all the rows in the dimension with the Sks that are not being used on the fact tables. I wrote a query to get all the Sks that are not being used. Now how