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.

Similar Messages

  • 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"... 

  • 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)

  • 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;

  • 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 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

  • 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.

  • 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);
           }

  • 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.

  • 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();
         }

  • Can not get output from Objective DAC without Pulseaudio [SOLVED]

    I have owned the ObjectiveDAC/O2 Amp combo for a couple of months now. Unfortunately I was unable to get the device to function properly without pulseaudio installed. When trying to configure it on a pure alsa system, I can set it as the default control card in alsamixer. The issue is that when I set it as the default pcm device, it fails to work. I can select the device in pulseaudio fine, and my system recognizes the device in alsa, however I cannot, for some reason, actually use the device. It seems that pulseaudio butchers sound quality, and I would greatly appreciate any help being able to get my device working without it. I can't believe that any sane individual would actually make part of the audio stack downmix audio by default.
    It was just a lack of understanding of Alsa's config syntax. I do apologize for taking up space on the forums. I now have Alsa running with my DAC just fine.
    Last edited by agahnim (2015-05-01 13:50:28)

    Yeah that's what I meant. Try to burn a new cd at a slower speed. When the new one is done create a hashsum of the new burn and compare it to the iso you used to burn it with. I only say this because a few times in the past when I had sr0 errors while booting live cds it was because the disk was messed up and I had to burn it again.

  • 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;

  • Can't get output from a MessageDialog

    Hello all JAVA-proggers,
    I have a problem, and i don't know what it is.
    I have a button on my screen an if i push the button a input dialog must appear.
    That;'s all fine, but what the user puts in the dialog screen is not pick up by my program.
    You can see the here.
    After input is given, i has to be added to the database.
    For error checking i have added a println with the user input, but nothing happens :(
    Hope someone can help me...
        private void btnAddCashActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
            if (selectedCustomer == null){
                JOptionPane.showMessageDialog(null, "Selecteer een barklant!","INPUT_ERROR", JOptionPane.INFORMATION_MESSAGE);
            else {
            String addCash = JOptionPane.showInputDialog(this, "Hoeveel moet er bij geschreven worden?","ADD_CASH",JOptionPane.QUESTION_MESSAGE);
            System.out.println("user input addCash: "+addCash);
            int id = selectedCustomer.getId();
            Customer newCustomer = new Customer(addCash, id);
            theAdmin.cashCustomer(newCustomer);
            selectCustomerId();
            showCustomer(selectedCustomer);
        }

    For error checking i have added a println with the
    user input, but nothing happens :(What do you mean? It doesn't print:
    user input addCash: xxxx
    at all? Then you aren't executing what you think you are (didn't recompile it? have a different version of that class in your classpath?). Or it threw an exception that you swallowed somewhere, or? You need to do more debugging.

  • Audigy 2 plat- cannot get sound from headphone output, only from rear pa

    I hjave installed the card but have not been able to get output from the headphone jack omn front panel. everything else works fine.

    Inertia22 wrote:
    I put in the Audigy 2 zs from my old PC into my new one and I cant get any sound from the Headphones or Mic.
    Only sound from the external speakers. Any help would be greatly appreciated.
    If you getting sound from the external speakers....are we talking the ones on the laptop?
    Means you still have the onboard sound turned on at a guess.

  • Getting output in excel sheet from jsp file

    Hi,
    I am a new programmer. I am trying to get output in excel sheet by clicking a link on page. I have used that 2 statements
    response.setContentType("application/x-download");
    response.setContentType("application/Octet-Stream");
    response.setHeader("Content- disposition","inline;filename=refdsxresults.xls");
    But it is giving an empty excel sheet. I don't know how to put the data in that sheet which is retrieved by using the query below.
    "select p.port_no,p.block_no,p.slot_no,p.channel_no,p.ref_no,"+
    "p.rr,c.card_type,c.work_or_protect,p.port_status_code,p.tr_id,"+
    "p.dest_rr,p.dest_shelf,p.dest_jack,p.mux,"+
    "sid.work_order_number,sid.pon_a,sid.pon_z,"+
    "sid.circuit_id,sid.account_name,sid.account_no,sid.order_no,sid.item_no,"+
    "sid.a_city_code,sid.z_city_code,p.parent_port_no "+
    "from eon_port p,eon_card c,sonet_item_detail sid "+
    "where p.logical_flag='N' and p.card_no*=c.card_no and "+
    "p.current_path_no*=sid.path_no and sid.action!='DISC' and sid.item_status!='CN' "+
    "and p.equip_no="+equipNumber+
    " order by p.ref_no";
    and also can I use the HTML to get this result in the browser. Could you please give an example. I need it urgently.
    Thanks in advance

    In an earlier post, somebody was saying that you can use regular HTML tables to output an XLS file. I've never tried it, so I don't know it to be true, but give it a look:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=407280&tstart=0&trange=15
    If that doesn't work, you can always return a CSV file (comma seperated values).

Maybe you are looking for

  • Error on generating reports from forms -- 499 Oracle SSO

    hai friends.. while am tryng to generate a report from a form(without passing any parameters), am geting the following message: *499 Oracle SSO* Oracle SSO am posting my code used: PROCEDURE RUN_REP_RRO ( ip_report_name_incl_path VARCHAR2, ip_report_

  • Obsolete Transactions in ECC 6.0

    Dear All, How to find what are the Transactions are obsolete in ECC 6.0 ? Note:PRGN_CORR2 Table doesn't contains all Transaction Details. and RODIR table contains only obsolete Function Module names. Thanks in Advance. Kanagaraja L

  • Daily Report Layout Customization

    Is it possible to customize the layout in the Daily Report - LABOR tab? I wish to rearrange the column order and the widths. It is possible at the Daily Report level but I don't see how it is possible at the Tab level...

  • How can forbid changging data when using BAPI  'BAPI_MATERIAL_SAVEREPLICA'?

    I am using BAPI  'BAPI_MATERIAL_SAVEREPLICA' to creat material master data in batch. But this BAPI also can be used for change mode. How to forbid the change of MAT data when use this BAPI? TKS a lot~~ I am looking foward to your response~~~ Edited b

  • 10.5.7 Update Correlates With Fans Running Continually

    After updating to 10.5.7, my MacBook's fans seem to run continually. If I Restart, they will stop for about 10 minutes, then return to continual running. As possible solutions, I tried: - zapping the PRAM, - reinstalling the update. Neither worked. H