Listening to unix commands from java in background?

How do i set up a java app in the background to listen to standard-in without hogging standard-in from the OS.

Hi ,
this is an example code to check the OS before running the command :
try{
int ch;
Process proc ;
Runtime r=Runtime.getRuntime();
StringBuffer sbuf = new StringBuffer();
String dir = new String();
String osname = System.getProperty("os.name");
if(osname.equals("Windows NT") )
proc = r.exec("cmd /c dir");
if(osname.startsWith("Linux") )
proc = r.exec("df -k");
InputStream is = proc.getInputStream();
while((ch=is.read() ) != -1)
sbuf.append((char)ch);
is.close();
dir = sbuf.toString();
System.out.println(dir );
}catch(Exception e){ System.out.println(e.getMessage());}
bye
Taha

Similar Messages

  • Call an interactive UNIX command from java

    Hi,
    I want to call a UNIX command from java. When issue the command 'htpasswd -c filename username' on UNIX terminal, it asks for the new password and the then confirmation password again (yeah, unfortunately the htpasswd installed on our system does not allow you proivde the password on the command line. So have to work interactively ). Now, I have written a simple java program RunCommand.java. I am hardcoding the password for the htpasswd command in the file (in the real situation, password will be generated dynamically). I want to issue 'java RunCommand' on the UNIX command line and get back the command prompt without being asked for the password twice. The code is below, but the Outputstream does not work as expected. It always asks for inputs. Any idea? Many thanks.
    import java.io.*;
    public class RunCommand {
    public static void main(String args[]) throws Exception {
    String s = null;
    try {
    String cmd = "htpasswd -c filename username ";
    // run a Unix command
    Process p = Runtime.getRuntime().exec(cmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    OutputStream stdOut = p.getOutputStream();
    String pswd = "mypassword";
    while ((s = stdInput.readLine()) != null) {
         s = stdInput.readLine();
         stdOut.write(pswd.getBytes());          
         stdOut.flush();
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null) {
    System.out.println(s);
    stdOut.close();
    stdInput.close();
    stdError.close();
    System.exit(0);
    catch (IOException e) {
    System.out.println("exceptions caught: ");
    e.printStackTrace();
    System.exit(-1);

    There are only about 9 billion responses a day on how to do this. Use the search feature.

  • Execute unix commands from Java

    Hi,
    I have a client application running on windows. This client should connect to a unix server and check for the existence of a file and display the result as "File found/File not found". In order to connect from windows to the unix server, I used the sockets and the connection is successfully established. The second part is to check for the presence of the file in unix server. I searched in google.com and the option I found to execute a unix command from java is the "Runtime.exec()". Runtime.exec is considered as the less effective (not a favorable) one.
    Is there any other option available (other than the Runtime) to execute the unix command from java? Can you please let me know.
    Thanks a lot
    Aishu

    So, please let me know how I can execute the above unix commands without Runtime.exec()You have a client and a server.
    You want something to run on the server, not the client.
    That means that something must in fact being running on the server before the client does anything at all.
    For example telnet. Or a J2EE server application.
    So is something like that running?
    If not then there absolutely no way to do what you want, even with Runtime.exec().
    If yes then what you do depends on what is running. So Runtime.exec() would be pointless if a J2EE server was running.

  • Issueing unix command from java

    I am using FTPConnection.java by Bret Taylor, for uploading files to remote linux portal. But i cannot issue any unix command from it . please anyone help me in this case?

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    It'll explain it all. - MOD

  • Calling a Unix Command from Java

    Hi all,
    I'm not a Java guy, I need a small help, I need a code which will call a Unix Command called from a Java code. For Example I need a Java code whereby I should be able to do a 'ls -lt' on my Unix box. Can anybody please help.
    Thanks,
    Shantanu

    See Runtime.exec()

  • Unable to excute unix command from java program

    import java.io.File; // is java code
    public class RunSystemCommand {
    public static void main(String args[]) {
    String s = null;
    // system command to run
    String cmd = "ls ";
    // set the working directory for the OS command processor
    File workDir = new File("c:/cygwin/cygwin");
    Process p = Runtime.getRuntime().exec(cmd, null, workDir);
    p.waitFor();
    I am tryiing to excute above code to run unix command on cygwin but gave folllowing error...... but works well to open a note pad..
    Exception in thread "main" java.io.IOException: CreateProcess: C:/cygwin/bin err
    or=5
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at d.main(d.java:19)
    It seems using this functionone cannot excute unix commands..please help to do so..

    Are you sure you want cygwin/cygwin?
    the following works fine for me, you may need change the workDir to your bin folder
    import java.io.File; // is java code
    import java.io.InputStream;
    public class RunSystemCommand {
        public static void main(String args[]) throws Throwable {
         String s = null;
         // system command to run
         String cmd = "ls ";
         // set the working directory for the OS command processor
         File workDir = new File("c:/cygwin/bin");
         Process p = Runtime.getRuntime().exec(cmd, null, workDir);
         InputStream pis = p.getInputStream();
         while( pis.read() != -1 ); // added, as otherwise the ls hangs.
         p.waitFor();
    }

  • Using Unix commands from Java Application

    Hi,
    I need to write an Java application such that could run Unix commands in a Unix box.
    For example, my Java app needs to log in the Unix box, change directory (cd), create new folder (mkdir), list the current files in folder (ls), mount a new device (mount), etc.
    Thank you very much.
    Hung

    you can use java.lang.Runtime.exec to invoke OS commands, but if you're going to be completing a sequence that complicated and need to manage error handleing well, it might be best to just invoke a native method or write a shell script that does all of that stuff and then invoke that script via Runtime.exec . The Runtime class has limitations when you start invoking processes that require user input (like 'su'). Search the forums for more extensive examples on how to use Runtime.

  • Execute Unix command from Java program running on windows

    Hello,
    I need to write a java program that fetches file count in a particular unix machine directory. But java program will be running on windows machine.
    The program should execute unix list command and fetch the output of that command.
    Can anyone help me on this?
    Thanks.

    Hi there,
    I had a similiar problem, though years ago. It was to have a java program execute any other. Lately, I've had to have a java program running on a unix machine execute a shell script. Entirely two different scenarios. I'm not sure what you will need for your app, but look into this:
    Java Native Interface for executing C/C++ code.
    C/C++ Code for launching the program you need to run.
    java.lang.Runtime(?).exec(....)
    With a combination of that stuff, you can make a launcher for any os that has Java running on it, and with Runtime, you can exec() pretty near any sort of unix shell or app command you'd like.
    Good luck.
    Tim

  • Running UNIX command from Java

    import java.lang.* ;
    import java.io.*   ;
    public class TestRunTime
        public static void main(String args[])
            int rc = -1 ;
            String yard = "psnsy" ;
            String ifwList = "[email protected],[email protected]" ;
            String cmd = "/usr/bin/mailx -r oracle -s \"PMC - Missing Interface Files from " + yard +
                               "\" " + ifwList + " < /interface/nwps/missingfiles.txt" ;
            rc = RunThis(cmd) ;
            System.out.println(rc) ;
        private static int RunThis(String str)
             Runtime rt = Runtime.getRuntime();
             int        rc = -1;
             try
                Process p = rt.exec(str);
                p.waitFor() ;
                BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line = "";
                while ((line = buf.readLine()) != null)
                   System.out.println(line) ;
                rc = 0 ;
                return rc ;
             catch ( Throwable t  )
                  t.printStackTrace();
                  rc = -1 ;
                  throw new RuntimeException() ;
    }When I run java TestRunTime
    all it does is hangs and never completes.
    I can run the string cmd from the UNIX shell and it runs as expected - I receive an email.

    jschell wrote:
    sabre150 wrote:
    Whether the detail is as you say or as I say does not remove the need to process the exec()ed processes stdout and stderr each in their own thread. Since the OP is not writing to stdin he can handle one of stdout or stderr in the Thread that invokes the exec() but the other needs a separate thread.If the streams are stripped from the process then...
    1. They should not be stripped until they are in their own thread.
    2. Each requires their own thread.
    But since the OP isn't stripping either, no other threads are needed. Nor does the OP need to strip them.I have to disagree. The following code is based on the traps article and sends output to stdout and to stderr from the 'sh' program. Run as is it deadlocks. Run by changing the 'false' to 'true' in the 'if' statement it does not deadlock.
    If one changes the code to process only stdout or stderr but not both then it deadlocks.
    Running the same code on Windows XP and Windows 2000 but using 'cmd.exe' instead of 'sh' and using 'dir' instead of 'ls' produces the same result.
    Running similar code that just runs a perl script without any stdin but that writes to both stdout and stderr it deadlocks if one does not process both stdout and stderr in separate threads.
    If one processes the Process stdout and stderr streams then one does not get a deadlock.
    This is entirely consistent with what the 'traps' article says and I hope consistent with what I have written in this thread.
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    class StreamGobbler extends Thread
        private int count = 0;
        private final InputStream is;
        private final String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                final InputStreamReader isr = new InputStreamReader(is);
                final BufferedReader br = new BufferedReader(isr);
                String line = null;
                while ((line = br.readLine()) != null)
                    System.out.println(++count + "\t " + type + "> " + line);
            } catch (IOException ioe)
                ioe.printStackTrace();
    public class Sabre20091015_2
        public static void main(String args[]) throws Exception
            final Process proc = Runtime.getRuntime().exec("sh");
            if (false)
                new StreamGobbler(proc.getErrorStream(), "ERROR").start();
                new StreamGobbler(proc.getInputStream(), "OUTPUT").start();
            final Writer writer = new OutputStreamWriter(proc.getOutputStream());
            for (int commandIndex = 0; commandIndex < 20000; commandIndex++)
                writer.write("echo Index " + commandIndex + "\n");
                writer.write("ls\n");
                writer.flush();
                writer.write("fnaskfdkdhflakjfljd\n");
                writer.flush();
            writer.close();
            final int exitValue = proc.waitFor();
            System.out.println("Exit value = " + exitValue);
    }

  • UNIX "export" Command from Java

    Hi,
    Am facing a problem while exeuting UNIX command from java. Am attaching the code which I am trying to execute.
    import java.io.*;
    public class RunCommandExample {
        public static void main(String args[]) {
            String s = null;
            try
                Runtime.getRuntime().exec("password=midware1");
                   //p = Runtime.getRuntime().exec("export password");
                   System.exit(0);
              catch (IOException e)
                System.out.println("[IOException]. Printing Stack Trace");
                e.printStackTrace();
                System.exit(-1);
    }This gives me the following error.
    [IOException]. Printing Stack Trace
    java.io.IOException: password=midware1: not found
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:52)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at RunCommandExample.main(RunCommandExample.java:24)
    Please let me know the solution for this problem.
    Waiting for your valuable replay..
    Thanks in advance,
    Ashly.

    Assigning and exporting variables are not commands that you can execute from Java. You can only execute programs--binary executables. Assigning and exporting shell or environment variables is part of the shell.
    Why are you trying to do this? Even if you could, it wouldn't affect the running VM, and it wouldn't affect anything outside that exec() invocation.
    If you need to set them for something else you're going to run, then you should set them in a shell script and run that script.

  • Call Unix Command From Reports Using Java

    Hi,
    Could somebody please show me a sample coding to call Unix command from 10g report using java?
    In metalink doc id 361857.1 does not show much.
    Thanks,
    neemin

    Hi,
    I have a problem with synchronization of the java commands.
    In the Before Parammeter Form trigger, I have:
    function BeforePForm return boolean is
    rt ORA_JAVA.JOBJECT;
    proc ORA_JAVA.JOBJECT;
    v_txt varchar2(32000);
    i integer := 0;
    v_cd_modulo int;
    v_arqlog text_io.file_type;
    cursor c_evento is
    select codigo,
    nome
    from
    (select e.cd_evento || e.cd_edicao codigo
    ,nm_evento nome
    from grh_ev_evento e
    where e.CD_GRUPO in (select cd_grupo
    from grh_ev_adm
    where cd_usuario = (select cd_usuario
    from usuario
    where login_usuario = :AUTHID)))
    order by substr(nome, 11);
    begin
    -- Create the context for logged user
    if instr(upper(nvl(:AUTHID,'RWCLIENT')),'RWCLIENT') > 0 then
    :AUTHID := :SSO_USUARIO;
    end if ;
    TCEENV.SET_TCEENV(:AUTHID);
    if PK_SCA.SCA_GET_USER_RIGHTS(:sca_module_name, :AUTHID) IS NULL then
    srw.message(100, 'Access denided!');
    return (FALSE);
    end if;
    -- Create file in Report Server (UNIX)
    v_txt := '<BR>' || htf.formSelectOpen('P_EV_EDICAO', 'Evento: ');
    :p_file := '/u03/SCAWEB/repout/' || :sca_module_name || '_' ||
    pk_sca.sca_encrypt(:AUTHID || to_char(systimestamp, 'ss.ff'));
    v_arqlog := text_io.fopen (:p_file, 'A');
    text_io.put_line (v_arqlog, v_txt);
    for reg in c_evento loop
    i := i + 1;
    if i = 1 then
    v_txt := '<OPTION SELECTED VALUE="' || reg.codigo || '">' || reg.nome;
    else
    v_txt := '<OPTION VALUE="' || reg.codigo || '">' || reg.nome;
    end if;
    text_io.put_line (v_arqlog, v_txt);
    end loop;
    v_txt := '</SELECT></CENTER></form></BODY> </HTML>';
    text_io.put_line (v_arqlog, v_txt);
    text_io.fclose (v_arqlog);
    SRW.SET_AFTER_FORM_HTML(SRW.FILE_ESCAPE, :p_file);
    rt := RUNTIME.GetRuntime();
    proc := RUNTIME.exec(rt,'rm ' || :p_file);
    return (TRUE);
    end;
    The problem is that there isn't a "synchronize" command, and the
    RUNTIME.exec(rt,'rm ' || :p_file) don't works (it does nothing) because
    the SRW.SET_AFTER_FORM_HTML has a large delay and the following
    command is ignored.
    How can I solve it?
    thanks,
    lmprestes

  • Unix and dos commands from Java

    How can I issue a unix command from a java program eg: setenv
    help would be appreciated

    setenv is a C shell builtin command. And it wouldn't make any sense to execute setenv from Java anyway, because the environment variable changes would only apply to that shell and possibly (if the variable is exported) to subprocesses.
    But look at the java.lang.Runtime.exec() method and the Process class.
    (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html)
    Be careful of input and output to the commands. If the command produces output and you don't read it from the getOutputStream(), your command will hang forever when the OS stdio buffer fills up. This can cause terrible random hangs. Search the forums for more on how to handle input and output. You'll probably need multiple threads to read/write the different streams. (stderr, stdout, stdin)

  • Executing UNIX command in Java

    I am having problems executing a command in Java. Here's the code I have for executing:
    Process p = Runtime.getRuntime().exec(cmd);
                                            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         while((display = input.readLine()) != null)
                             num_1 = Double.parseDouble(display);
                             percent = (num_1 * 100) / (50000000);
                        flip = 1;
                        catch(IOException e)
                        e.printStackTrace();     
                        System.exit(1);
    Now, when I run the script, I receive the following errors:
    Exception occurred during event dispatching:
    java.security.AccessControlException: access denied (java.io.FilePermission /Netadmin/UCDSNMP/bin/snmpdelta execute)
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.lang.RuntimeException.<init>(RuntimeException.java:47)
    at java.lang.SecurityException.<init>(SecurityException.java:39)
    at java.security.AccessControlException.<init>(AccessControlException.java:57)
    at java.security.AccessControlContext.checkPermission(Compiled Code)
    at java.security.AccessController.checkPermission(Compiled Code)
    at java.lang.SecurityManager.checkPermission(Compiled Code)
    at java.lang.SecurityManager.checkExec(SecurityManager.java:789)
    at java.lang.Runtime.exec(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at java.lang.Runtime.exec(Runtime.java:152)
    at snmp.actionPerformed(Compiled Code)
    at java.awt.Button.processActionEvent(Button.java:308)
    at java.awt.Button.processEvent(Button.java:281)
    at java.awt.Component.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.EventQueue.dispatchEvent(Compiled Code)
    at java.awt.EventDispatchThread.pumpOneEvent(Compiled Code)
    at java.awt.EventDispatchThread.pumpEvents(Compiled Code)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
    The user is entering the parameters for the UNIX command from a Java applet. Everything looks right, but I can't seem to run the file? Please help! All is appreciated.
    Jason Banks
    Northeastern University

    Sorry, this is a bug that I've reported -- see Sun's response and my original report (along with how to get around the problem) shown below:
    Hi Vira Van.,
    The bug you have reported is a duplicate of Bug ID: 4522533.
    Thank you for providing us with additional information
    that can be used in the resolution of this bug.
    This bug can be monitored via the the Java Developer
    Connection Bug Parade at:
    http://developer.java.sun.com/developer/bugParade/index.jshtml
    The Java Developer Connection is a free channel that is
    maintained by staff here at Sun.  Access this web page to join:
    http://developer.java.sun.com/servlet/RegistrationServlet
    The home page for the JDC is:
    http://java.sun.com/jdc
    Regards,
    Girish
    ----------------- Original Bug Report-------------------
    category : java
    release : 1.4
    subcategory : jar
    type : bug
    synopsis : signed applet: bad major version number on NN4.79 and ClassNotFound in IE5.5
    description : FULL PRODUCT VERSION :
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    FULL OPERATING SYSTEM VERSION : Windows 98 [Version
    4.10.2222]
    ADDITIONAL OPERATING SYSTEMS :
    BROWSERS: Netscape Navigator 4.79
            : Internet Explorer 5.5
    EXTRA RELEVANT SYSTEM CONFIGURATION :
    Applet failed to start in Netscape, the following error
    message appeared in the Java Console:
    Netscape Communications Corporation -- Java 1.1.5
    Type '?' for options.
    Symantec Java! ByteCode Compiler Version 210.065
    Copyright (C) 1996-97 Symantec Corporation
    # Applet exception: error: java.lang.ClassFormatError: Bad
    major version number
    java.lang.ClassFormatError: Bad major version number
      at java.lang.ClassLoader.defineClass(Compiled Code)
      at netscape.applet.AppletClassLoader.findClass(Compiled
    Code)
      at netscape.applet.AppletClassLoader.loadClass1(Compiled
    Code)
    * at netscape.applet.AppletClassLoader.loadClass(Compiled
    Code)
      at netscape.applet.AppletClassLoader.loadClass(Compiled
    Code)
      at
    netscape.applet.DerivedAppletFrame$LoadAppletEvent.dispatch(
    Compiled Code)
      at
    java.awt.EventDispatchThread$EventPump.dispatchEvents(Compil
    ed Code)
      at java.awt.EventDispatchThread.run(Compiled Code)
      at
    netscape.applet.DerivedAppletFrame$AppletEventDispatchThread
    .run(Compiled Code)
    The same applet
    A DESCRIPTION OF THE PROBLEM :
    Unable to run signed applet with Netscape 4.79 and IE5.5
    native JVM.
    REGRESSION.  Last worked in version 1.3.1
    STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
    1.compile program and copy class files to a temp directory
    2.sign the applet for Netscape as follows:
    signtool -k aok -d \progra~1\netscape\users\viravan -Z
    FIO.jar temp
    3.sign the applet for Internet Explorer as follows:
    cabarc -p n FileIO.cab FileIO*.class
    setreg 1 true
    makecert -sk aok -n "CN=aok" aok.cer
    cert2spc aok.cer aok.spc
    signcode -j javasign.dll -jp LOWX -spc aok.spc -k aok
    FileIO.cab
    Run the applet with the following HTML file:
    <html><head><Title>Self-Signed Applet</Title>
    <script>
    document.layers ? parm=1 : parm=0;
    </script>
    <body>
    This file I/O applet lets you read and write to the user's
    local disk.<br>
    <br>
    <script>
    document.writeln('<APPLET CODE = "FileIO" CODEBASE = "."
    ARCHIVE = "FIO.jar" WIDTH = 10 HEIGHT = 10 NAME = "JSF">');
    document.writeln('<param name="Netscape"
    value="'+parm+'">');
    document.writeln('<param name="cabbase"
    value="FileIO.cab">');
    document.writeln('</APPLET>');
    </script>
    </body>
    </html>
    EXPECTED VERSUS ACTUAL BEHAVIOR :
    A frame with a textarea and some buttons should popup in the
    center of the screen.
    ERROR MESSAGES/STACK TRACES THAT OCCUR :
    Applet signed with signtool failed to start in Netscape, the following error
    message appeared in the Java Console:
    Netscape Communications Corporation -- Java 1.1.5
    Type '?' for options.
    Symantec Java! ByteCode Compiler Version 210.065
    Copyright (C) 1996-97 Symantec Corporation
    # Applet exception: error: java.lang.ClassFormatError: Bad major version number
    java.lang.ClassFormatError: Bad major version number
      at java.lang.ClassLoader.defineClass(Compiled Code)
      at netscape.applet.AppletClassLoader.findClass(Compiled Code)
      at netscape.applet.AppletClassLoader.loadClass1(Compiled Code)
    * at netscape.applet.AppletClassLoader.loadClass(Compiled Code)
      at netscape.applet.AppletClassLoader.loadClass(Compiled Code)
      at netscape.applet.DerivedAppletFrame$LoadAppletEvent.dispatch(Compiled Code)
      at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
      at java.awt.EventDispatchThread.run(Compiled Code)
      at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
    Code)
    The same applet signed with signcode failed to start in Internet explorer, the
    error message in the Java Console is:
    Error loading class: FileIO
    java.lang.NoClassDefFoundError
    java.lang.ClassNotFoundException: FileIO
            at com/ms/vm/loader/URLClassLoader.loadClass
            at com/ms/vm/loader/URLClassLoader.loadClass
            at com/ms/applet/AppletPanel.securedClassLoad
            at com/ms/applet/AppletPanel.processSentEvent
            at com/ms/applet/AppletPanel.processSentEvent
            at com/ms/applet/AppletPanel.run
            at java/lang/Thread.run
    This bug can be reproduced always.
    ---------- BEGIN SOURCE ----------
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class FileIO extends Applet implements ActionListener {
       public static void main(String[] args) {
          new FileIO();
          F.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                System.exit(0);
       public void init() {
          String tmp=getParameter("Netscape");
          if (tmp!=null) {
             if (tmp.equals("1")) {
                try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");
                   NS=true;
                } catch (Throwable exception) {}
          new FileIO();
          F.setResizable(false);
       public void stop() {
          F.dispose();
       public FileIO() {
          newline=System.getProperty("line.separator");
          F.setLayout(new BorderLayout(0,0));
          String line,inbuf="";
          String newline=System.getProperty("line.separator");
          text=new TextArea(inbuf,24,80,TextArea.SCROLLBARS_BOTH);
          text.setFont(new Font("Courier",Font.PLAIN,12));
          text.setBackground(Color.cyan);
          text.setForeground(Color.black);
          F.add("Center",text);
          Panel pan=new Panel();
          pan.setLayout(new FlowLayout(1,0,0));
          pan.setBackground(Color.yellow);
          TF=new TextField(40);
          TF.setFont(new Font("Courier",Font.PLAIN,12));
          pan.add(TF);
          OP=new Button("Open");
          OP.addActionListener(this);
          pan.add(OP);
          FS=new Button("Save");
          FS.addActionListener(this);
          pan.add(FS);
          SA=new Button("Save-As");
          SA.addActionListener(this);
          pan.add(SA);
          reset=new Button("Reset");
          reset.addActionListener(this);
          pan.add(reset);
          F.add("South",pan);
          F.pack();
          Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
          Dimension size=F.getSize();
          int X=(screen.width-size.width)/2;
          int Y=(screen.height-size.height)/2;
          F.setLocation(X,Y);
          F.setVisible(true);
       public void actionPerformed(ActionEvent event) {
          String tmp="";
          String O=text.getText();
          StringTokenizer tkn=new StringTokenizer(O,newline);
          int ntkn=tkn.countTokens();
          Object ev=event.getSource();
          if (ev.equals(OP)) {
             FileDialog fd=new FileDialog(F,"File to open",FileDialog.LOAD);
             fd.setFile("*.java");
             fd.show();
             tmp=fd.getDirectory();
             if (fd.getFile()==null) {text.requestFocus(); return;}
             tmp+=fd.getFile();
             TF.setText(tmp);
             try {
                if (NS)
    {netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");}
                BufferedReader reader=new BufferedReader(new FileReader(tmp));
                String line;
                String crlf="";
                tmp="";
                while ((line=reader.readLine())!=null) {
                   tmp+=crlf+line;
                   crlf="\n";
                reader.close();
                text.setText(tmp);
             } catch (Throwable e) {
                e.printStackTrace();
          } else if (ev.equals(FS) || ev.equals(SA)) {
             try {
                if (ev.equals(SA)) {
                   FileDialog fd=new FileDialog(F,"File to save",FileDialog.SAVE);
                   fd.setFile("*.java");
                   fd.show();
                   tmp=fd.getDirectory();
                   tmp+=fd.getFile();
                } else {
                   tmp=TF.getText();
                if (tmp.length()==0) {text.requestFocus(); return;}
                if (tmp.indexOf(".java")<0) tmp+=".java";
                TF.setText(tmp);
                if (NS)
    {netscape.security.PrivilegeManager.enablePrivilege("UniversalFileWrite");}
                FileOutputStream fos=new FileOutputStream(tmp);
                BufferedWriter out=new BufferedWriter(new OutputStreamWriter(new
    DataOutputStream(fos)));
                for (int i=0;i<ntkn;i++) out.write(tkn.nextToken()+newline);
                out.flush();
                out.close();
                if (NS)
    {netscape.security.PrivilegeManager.revertPrivilege("UniversalFileWrite");}
                System.out.println(tmp+" saved");
             } catch (Throwable e) {
                e.printStackTrace();
          } else if (ev.equals(reset)) {
             text.setText("");
             TF.setText("");
          text.requestFocus();
       private String replace(String input, String srch, String repl) {
          int i=input.indexOf(srch);
          while (i>=0) {
             input=input.substring(0,i)+repl+input.substring(i+srch.length());
             i=input.indexOf(srch);
          return input;
       private Button OP,FS,SA,reset,TB;
       private boolean newLine,NS=false;
       private TextArea text;
       private TextField TF;
       private final char NL='\n';
       private String content,newline;
       private static Frame F=new Frame("FileIO");
    ---------- END SOURCE ----------
    CUSTOMER WORKAROUND :
    build the signed applet with SDK1.3.1 or make it a signed
    applet that uses Java Plugin 1.4.0 (i.e., sign it with jarsigner).
    workaround :
    suggested_val :
    cust_name : Vira Van.
    dateCreated : 2002-03-24 19:52:18.4
    dateEvaluated : 2002-04-01 18:48:10.858

  • How to execute unix command from ODI Procedure

    Hi,
    I am trying to execute below unix command from ODI Procedure (Command on Target tab) but I am getting the error "java.io.IOException: Cannot run program "cd": error=2, No such file or directory" but when I try to execute the same command using OdiOSCommand, it is executing successfully. I don't want to use shell script to execute this command. Is there any specific syntax am I missing to execute this command from ODI procedure?
    cd /project3/tmt/;ls *.dmp > dmplist.lst
    Please help me on this...
    Thanks
    MT

    Hi nahlikh,
    Thank you for the reply.
    I used below command in Procedure but still getting the same error as "java.io.IOException: Cannot run program "OdiOSCommand": error=2, No such file or directory".
    OdiOSCommand "-COMMAND=cd /project3/tmt/;ls *.dmp > dmplist.lst"
    as I mentioned earlier if I use the command cd /project3/tmt/;ls *.dmp > dmplist.lst in OdiOSCommand tool it is executing successfully without any issues.
    any thoughts appreciated to get a solution for this issue.
    Thanks
    MT

  • How to run a unix command in java

    Hi all,
    I need to run a unix command in my standalone java application.my java program is in windows.Is it possible to run unix command on windows system.help me out.
    I tried this
    Process p = Runtime.getRuntime().exec("ps -ef");
                BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p.getInputStream()));
                BufferedReader stdError = new BufferedReader(new
                     InputStreamReader(p.getErrorStream()));i get IO Exception -Create Process ps-ef error=2

    If you want to run a command from java for a windows platform, you should check windows knows the command.
    So, load up a DOS prompt and type ps -ef and see what happens.

Maybe you are looking for

  • Adobe Reader won't DL - need a pdf reader [Lumia 7...

    So I have a slight problem with Lumia 710. After I figured out how to get a .pdf file onto my device (did so via Skydrive) - it suggested that I DL a pdf reader and directed me to Adobe Reader.  However, once I get to that page, I get:  "App not avai

  • BAPI for transaction CJ30 ?

    I wanted to know if any BAPI/BADI exists for transaction CJ30 . Thanks in advance . Ambar .

  • Incorrect Decimal Notation

    Hello All ,               For some of our New Hires are facing Issues during Enrolling for Medical. It displays as u201C22,00u201D instead of u201C22.00u201D and it gives them an error after the election. I can do for single user through SU01 and sav

  • 35MM Camera for Black and White Photography.

    What are good 35MM Cameras for black and white photography?

  • Is IR receiver 5189-0959 Rev B equivalent to IR receiver 492936-001 Rev A?

    I have a IR receiver P/N 492936-001 Rev A.  It works with windows 7 and windows 8 and all 5 of my computers with TV cards.  I purchased several IR receivers, P/N 5189-0959 Rev B that were supposed to be equivalent.  They look almost identical.  The R