Capturing the output of a os command line

I need to capture the output of a os command line executed from one java program and I don't know how can do it.
For example:
Runtime.getRuntime().exec("hostid");

Your suggestion worked very well, just in case that this could interest somebody, this is the complete solution
Thanks for your help
import java.io.*;
public class HostID
public static void main(String args[]){
try{
InputStream in = (Runtime.getRuntime().exec("hostid")).getInputStream();
byte[] arreglo= new byte[200];
int cantidad = in.read(arreglo);
System.out.println(new String(arreglo,0,cantidad));
} catch (IOException ioe){System.out.println(ioe.getMessage());}
}

Similar Messages

  • To capture the output

    Hi all ,
    I Wish You A Happy New Year!!!!!!!!
    I am trying to capture the output of a java program into a file i.e,when I run the java program at command prompt and get the output, the output must be automatically captured into a file is this possible using java code
    Please help me
    Thanks,
    raghu

    And Mac OS/X is a unix variant, so it works there too.
    You can also redirect standard output in Java itself by using System.setOut, but once you're altering the Java code, I'd suggest refactoring the code so that it doesn't send all its output to standard output necessarily.

  • How to change a setting in the Java Control Panel with command line

    Hi,
    I am trying to figure out how to change a setting in the Java Control Panel with command line or with a script. I want to enable "Use SSL 2.0 compatible ClientHello format"
    I can't seem to find any documentation on how to change settings in the Java Control Panel via the command line
    Edited by: 897133 on Nov 14, 2011 7:15 AM

    OK figured it out. This is for the next person seeking the same solution.
    When you click on the Java Control Panel (found in the Control panel) in any version of Windows, it first looks for a System Wide Java Configuration (found here: C:\Windows\Sun\Java\Deployment). At this point you must be wondering why you don't have this folder (C:\Windows\Sun\Java\Deployment) or why its empty. Well, for an enterprise environment, you have to create it and place something in it - it doesn't exist by default. So you'll need a script (I used Autoit) to create the directory structure and place the the two files into it. The two files are "deployment.properties" and "deployment.config".
    Example: When you click on the Java Control Panel it first checks to see if this directory exists (C:\Windows\Sun\Java\Deployment) and then checks if there is a "deployment.config". If there is one it opens it and reads it. If it doesn't exist, Java creates user settings found here C:\Users\USERNAME\AppData\LocalLow\Sun\Java\Deployment on Windows 7.
    __deployment.config__
    It should look like this inside:
    *#deployment.config*
    *#Mon Nov 14 13:06:38 AST 2011*
    *# The First line below specifies if this config is mandatory which is simple enough*
    *# The second line just tells Java where to the properties of your Java Configuration*
    *# NOTE: These java settings will be applied to each user file and will overwrite existing ones*
    deployment.system.config.mandatory=True
    deployment.system.config=file\:C\:/WINDOWS/Sun/Java/Deployment/deployment.properties
    If you look in C:\Users\USERNAME\AppData\LocalLow\Sun\Java\Deployment on Windows 7 for example you will find "deployment.properties". You can use this as your default example and add your settings to it.
    How?
    Easy. If you want to add *"Use SSL 2.0 compatible ClientHello format"*
    Add this line:
    deployment.security.SSLv2Hello=true
    Maybe you want to disable Java update (which is a big problem for enterprises)
    Add these lines:
    deployment.javaws.autodownload=NEVER
    deployment.javaws.autodownload.locked=
    Below is a basic AutoIt script you could use (It compiles the files into the executable. When you compile the script the two Java files must be in the directory you specify in the FileInstall line, which can be anything you choose. It will also create your directory structure):
    #NoTrayIcon
    #RequireAdmin
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseX64=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    Func _JavaConfig()
         $ConfigFile_1 = @TempDir & "\deployment.properties"
         $ConfigFile_2 = @TempDir & "\deployment.config"
         FileInstall ("D:\My Documents\Autoit\Java config\deployment.properties", $ConfigFile_1)
    FileInstall ("D:\My Documents\Autoit\Java config\deployment.config", $ConfigFile_2)
         FileCopy($ConfigFile_1, @WindowsDir & "\Sun\Java\Deployment\", 9)
         FileCopy($ConfigFile_2, @WindowsDir & "\Sun\Java\Deployment\", 9)
         Sleep(10000)
         FileDelete(@TempDir & "\deployment.properties")
         FileDelete(@TempDir & "\deployment.config")
    EndFunc
    _JavaConfig()
    Now if you have SCUP and have setup Self Cert for your organization, you just need to create a SCUP update for JRE.
    Edited by: 897133 on Nov 16, 2011 4:53 AM

  • How to capture the output of another program into a File/String

    I needed to capture the output of a dos program in an String/file I tried doing Runtime.getRuntime.exec("ipconfig /all >tmp.txt");
    but still I am unable to capture the output frm the program which I would like to capture in a file or String.Can anyone help

    When you use the Runtime.exec() method, it returns a Process object, that process object has access to the streams; stdout, stdin, and stderr of the application you just executed. what you'll want to monitor is the stdout or stderr streams using the
    p.getInputStream() or p.getErrorStream(), where p = the process object returned via the Runtime.exe() method.

  • Capturing the output of a jsp page and save that output in a WORD .doc file

    Hi,
    This is Naveen. I got stuck up with a problem/doubt. URGENT ! URGENT !
    My doubt is how to capture the output of a jsp page(the content is dynamic generated) and save that output to a MS-Word doc file.
    I know that therez an option of using Servlets Filters, but this concept is supported by Servlet 2.3 spec. and not earlier. And we are working on previous spec. and our web-servers also supports the prev. version and not the 2.3 version.
    If incase, therez a third-party utility for free usage, suggestions are appreciated.
    Hope most of them came across this kind of functional requirement. If anyone of them succeeded in this, please express ur bitter experience if any, faced during the coding.
    Thanks in Advance for help.
    Naveen

    You can set the MIME content type as .doc and try to open the Page.
    res.setContentType("application/vnd.ms-excel"); to generate the Page output as Excel
    res.setContentType("application/vnd.ms-word"); to generate the Page output as MS Word doc
    Hope this helps..

  • Capturing the Output of a webservice on an APEX form

    Hi,
    I have created an application that calls a Webservice (BPEL process). The application has a single form that takes in a single field (ReviewDate) and calls the Webservice. The Webservice does its thing and returns a mesage "The review date has been accepted".How do I capture this message in my form? I have the placeholders for input and output parameters but the output is not returned to the form. What do I need to do capture this message?
    Also, please note that the webservice does its thing successfully. I only need to capture the output of the webservice in my form.
    Thanks
    Vijay

    You can set the MIME content type as .doc and try to open the Page.
    res.setContentType("application/vnd.ms-excel"); to generate the Page output as Excel
    res.setContentType("application/vnd.ms-word"); to generate the Page output as MS Word doc
    Hope this helps..

  • Capturing the output from jsp selvlet

              Hi,
              I have a requirement where I need to capture the output of the JSP generated servlet
              , and do something with it before it get's to the client side.
              Has someone done something like this before.Any ideas, suggestions .
              Thanx,
              Tajdar
              

    You can set the MIME content type as .doc and try to open the Page.
    res.setContentType("application/vnd.ms-excel"); to generate the Page output as Excel
    res.setContentType("application/vnd.ms-word"); to generate the Page output as MS Word doc
    Hope this helps..

  • Capturing the output of a javax.sound.midi.Synthesizer

    Hallo,
    since i can�t convert a MIDI-Sequence to a WAV-File directly, i want to play back the Sequence and capture the sound somewhere "between" the sound-generating synthesizer and the speakers. As far as i understand, i have to obtain a TargetDataLine from an output mixer, so i can read the sound data, since ports aren�t implemented yet. My problem is: How can i obtain such a TargetDataLine?
    With something like
    info = new DataLine.Info(TargetDataLine.class, format);
    line = (TargetDataLine)AudioSystem.getLine(info);
    i get a line to capture microphone input.
    i managed to get a mixer that is opened and started, when the synthesizer is opened, but that mixer only provides com.sun.media.sound.MixerSourceLines.
    Any help will be greatly appreciated.

    Not a reply, I'm afraid.
    I want to combine Midi output with audio output, which is exactly the same question as this thread. The whole thrust of Java sound is to 'unify' Midi and Audio, and yet I've fallen at the first hurdle.
    This thread was opened in Nov last year, yet is still unanswered. Is this right?

  • How to remove truncation in the output of ps -ef command in solaris

    Hi,
    One silly question but i m unable to find solution.
    In solaris-10 when i executed the command ps -ef some datas in the output in the command column is truncated as below
    UID PID PPID C STIME TTY TIME CMD
    root 6811 1 0 19:33:36 pts/3 0:00 sh /export/home/bti/bti/Revathi/BTI/EMS/bin/startemsserver.sh
    root 6827 6819 0 19:33:37 pts/3 2:33 /export/home/bti/bti/Revathi/BTI/EMS/jre/bin/java -DJBOSS_HOME=/export/home/bti
    Where in the CMD column the path */export/home/bti/bti/Revathi/BTI/EMS/jre/bin/java -DJBOSS_HOME=/export/home/bti* continues. Only half of the path is shown. I need the entire path how to achieve it
    Regards
    Revathi

    Just to make things a little more complex...
    /usr/ucb/ps (actually /usr/ucb/sparcv9/ps) used to be SUID root so that it could read the full args directly out of the address space of the process (/proc/<pid>/as).
    Sun removed this behavior in Solaris 8 with patch 109023-05 and in Solaris 9 with patch 120240-01 (it's been removed from Solaris 10 since FCS)

  • The Problem about using OTT command line

    Environment variables:
    oracle_home=c:\oracle
    command line:
    ott userid=scott/tiger intype=demoin.typ outtype=demoout.typ code=cpp hfile=demo.h cppfile=demo.cpp mapfile=RegisterMappings.cpp
    error message:
    Exception in thread "main" java.lang.NoClassDefFoundError: oracle/ott/c/CMain
    where should I place the all the classes(not only the CMain.class) of oracle package?
    or what others should I have to configure?
    thanks!

    install xe client
    set ORACLE_HOME to the client installation path.
    ******************************ott.bat******************************
    @echo off
    Rem OTT script for Oracle XE .
    Rem Before running this script
    Rem set jdk1.4.2/bin to PATH
    Rem If ORACLE_HOME is not set, set the
    Rem CLASSPATH to the directories containing
    Rem ojdbc14.jar,orai18n.jar and ottclasses.zip
    Rem
    if defined ORACLE_HOME set CLASSPATH=%ORACLE_HOME%\jdbc\lib\ojdbc14.jar;%ORACLE_HOME%\jlib\orai18n.jar;%ORACLE_HOME%\precomp\lib\ottclasses.zip;%CLASSPATH%
    set NLSLANG=
    if defined NLS_LANG set NLSLANG=NLS_LANG
    if defined ORACLE_HOME (
    java oracle.ott.c.CMain nlslang=%NLSLANG% orahome=%ORACLE_HOME% %*
    ) else (
    java oracle.ott.c.CMain nlslang=%NLSLANG% %*
    )

  • How to capture the calculated (using pricing engine ) quote line price

    Hi everyone,
    Need some help.
    Can anybody explain me:
    How to capture the quote line price on run time when the pricing engine is invoked and at the same time this calculated quote line price should not get updated in the base table(Quoting module in CRM).
    Please help me.
    Thanks,
    Srinivas
    Edited by: user0232 on Aug 26, 2011 8:21 AM

    Hi,
    Which cost to capture is depends on Costing and valuation varients
    Got to OKP6 or OKP8
    Select valuation varient >>> Maintain strategy sequence under MATERIAL VALUATION
    Which system can take first Variable or standard.
    Kapil

  • Using a the string args to input command line numerical input

    Hello,
    I am trying to allow the user to input a number from the command line to set up the number of elements in an array. I am having trouble converting the string info to int. Could someone post an example of how this is possible? Or a way to read a string for a numerical value?
    Example:
    nameofprogram 105 (so this means they want a 105 element array create when the program starts)
    Message was edited by:
    2disbetter

    try this
    public class Test {
         public static void main(String[] args)
              final int i = Integer.parseInt( args[0]);
              int[] a = new int;
              System.out.println(a.length);
    if you have to have variable in size part of the array object creator it needs to be final.

  • How change the wallpaper/background with a command line ?

    Hi people,
    did someone know how change the wallpaper with a command line ?
    thx a lot

    Hi,
    I think this can be done with PowerShell. We could create a function to set wallpaper:
    Function Set-WallPaper($Value)
     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
     rundll32.exe user32.dll, UpdatePerUserSystemParameters
    Open PowerShell; paste the function above in it to make this function work.
    Now, if you want to change some wallpaper, you could type the following text:
    Set-WallPaper -value "the path of you wallpaper"
    If you are interested, I would like to share the following article with you for your reference:
    Hey, Scripting Guy! How Can I Hide
    My Desktop Wallpaper?
    If you need some help on writing this script, you can also post your question to The Official Scripting Guys Forum:
    The
    Official Scripting Guys Forum
    Hope this helps. Thanks.
    Alex Zhao
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Capturing the output of a JSP page as HTML

    Hi,
    Can anyone tell me if this is possible. I have a JSP page that contains
    information about an order that was just entered (Essentially a
    confirmation page). What I want to do is somehow intercept the output
    stream inside the JSP page and write it to a file, as plain html, which
    I
    will later attach to an email and send to someone.
    Thanks,
    Jordi
    Jordi Pinyol Essi Projects
    Ingeniero de Desarrollo
    [email protected] t +34 977 221 182
    http://www.essiprojects.com f +34 977 230 170

    You won't be able to "intercept" the output since it is the JSP page itself that is doing the writing.
    Will the file that you write the output to reside on the client side or the server side? It sounds like you want to receive the HTML output not as something to view on the browser, but a file you can save and send and use later. If this is the case, one technique that might work is to take advantage of the servlet name mapping feature that is available for registered JSP pages.
    Assuming your JSP pages are registered, you would map your JSP page like:
    <servlet>
    <servlet-name>confirmation</servlet-name>
    <jsp-file>confirmation.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>confirmation</servlet-name>
    <url-pattern>/confirmation.out</url-pattern>
    </servlet-mapping>
    What happens is that a request for the URL /NASApp/myapp/confirmation.out gets mapped to the confirmation.jsp JSP page. If you set your MIME type correctly in the JSP page, the HTML output from the JSP page is not properly recognized by the browser causing it to prompt you to save the file.
    I have used this technique to generated CSV files from a JSP page. The browser is completely fooled.
    JC
    Jordi Pi?ol wrote:
    >
    Hi,
    Can anyone tell me if this is possible. I have a JSP page that contains
    information about an order that was just entered (Essentially a
    confirmation page). What I want to do is somehow intercept the output
    stream inside the JSP page and write it to a file, as plain html, which
    I
    will later attach to an email and send to someone.
    Thanks,
    Jordi
    Jordi Pinyol Essi Projects
    Ingeniero de Desarrollo
    [email protected] t +34 977 221 182
    http://www.essiprojects.com f +34 977 230 170

  • Capture the output of ExceptionDescribe

    I have some C++ code which calls Java code through the Invocation API:
    jType type = env->SomeJNICall();
    if ( type == NULL || env->ExceptionOccurred() )
         env->ExceptionDescribe();Instead of spitting out the exception description to stdout (or stderr?) is there a way of capturing the text and putting it into a std::string or copying it into a memory location pointed to by a char *?
    Thanks!

    I believe the API can be used to return the actual exception. With that, you can get its class, and with its class you can call methods of the exception object. (All, of course, via JNI.)

Maybe you are looking for