"at" UNIX Command in Java Program

Friends,
1. "at" command in UNIX execute Unix command at a scheduled time. 2. For each user there will be a table maintained internally which can be accessed by "at" with "-l" argument.
3. A mail will be sent to the owner with the output of the commands as a message.
I tried to run the "at" command of Unix in JSP, which gets succesfully executed in Oracle 10g App Server container (Installed in Solaris machine). I have tested the successful execution of command with the log file. But I haven't got any mail for the output. If anyone had any idea, please help me.
The code I have wtitten is
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(new String[] {"sh","-c","at 2115 Dec 7 < /export/home/usr1/abc.sh"});
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
logger.info("<ERROR>");
while ( (line = br.readLine()) != null)
logger.info(line);
logger.info("</ERROR>");
int exitVal = proc.waitFor();
logger.info("Process exitValue: " + exitVal);
My doubts are:
1. Who is the owner of the output of "at"command, which gets executed under Oracle 10g App Server container?
2. If no one is the owner, then where will the output of "at" command will go?
3. Is there any other way to execute "at" command of UNIX in java program? If so, then please help me.
Thanks in advance.
regards
Nandha Kumar.M

filestream I have to ask - what's a chav ?
I have doubts abut what it is :-)
Seriously though, what is that an abbreviation for?
That's a new one to me.
http://www.chavscum.co.uk
chavs are roughly analogous to rednecksI wouldn't use that analogy. While both may lack certain social graces, rednecks typically don't receive ASBOs.
Chavs favor small cars with lots of bling whereas rednecks are likely to drive a pickup or a large sedan.
Chavs have pitbulls in their yards (gardens), rednecks an '84 Mustang LX on cinder blocks.
etc, etc.
Message was edited by:
filestream
Message was edited by:
filestream

Similar Messages

  • 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

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

  • 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 command using java

    Hello
    Can we execute a unix command using java? If it is how we can execute. Is this affect the performance of the program.
    Thanks

    I tried what you said. But its not working and returning error message,
    java.io.IOException: CreateProcess: ls -a error=2
         at java.lang.ProcessImpl.create(Native Method)
         at java.lang.ProcessImpl.<init>(Unknown Source)
         at java.lang.ProcessImpl.start(Unknown Source)
         at java.lang.ProcessBuilder.start(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
    If i try this statement,
    Runtime.getRuntime().exec("c\windows\notepad");
    It is working fine.
    Any idea about this.
    Plz ...........

  • Invoking Unix command with java stored procedure

    Hi,
    I have a perfectly working environment and now I am trying to replicate the same in another server. I have a java stored procedure which invokes the Unix command using java Runtime.exec() in my code named "run". I am sure that the code is called and the java class run is resolved in oracle as I could see that in dba_java_resolvers dictionary. But I am not sure whether the function in java is called or whether a exception is thrown. how to identify this? Could there be any thing to do with settings in oracle side? please help me.
    Thanks in advance,
    Marutha

    Hi,
    Do you get any output while running the code?
    I'm testing similar solution and if there are any errors or Oracle can't execute the program due to permissions or other issues the error information will be displayed. Also in the Java class itself you need to catch exceptions and print stack trace to standard output.
    declare
    x number;
    begin
    dbms_output.enable(1000000);
    dbms_java.set_output(1000000);
    x:=system_command.run_command('testconnect.sh');
    dbms_output.put_line('Returned value='||x);
    exception
    when others then dbms_output.put_line('Sql error='||substr(sqlerrm,1,250));
    end;
    <system_command.run_command> - replace with a call to your java stored procedure.

  • How to execute unix command in java  or jsp

    have a peace day,
    please send some sample code for
    "execute the unix command in java or jsp"
    thank you
    regards
    rex

    i execute this coding
    its compiling. while running i get the error " java.io.IOException: CreateProcess: \ls-l error=2 "
    import java.io.*;
    import java.util.*;
    public class Test
       public static void main(String[] args) throws Exception
         try
              String[] cmd = {"/ls-l"};
    Runtime.getRuntime().exec(cmd);
         catch (Exception e)
               System.out.println(e);
      }what can i do for that
    thank u

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • Problem in executing a unix command through java

    hi
    i'm trying to execute unix command through java
    simple shell command like "ls -l >test " but i'm not able to see the result.
    there are no error messages.
    Code is:
    import java.lang.Runtime.*;
    class ExecDemo
         public static void main(String[] args)
              Runtime r=Runtime.getRuntime();
              Process p=null;
              try
                   p=r.exec("ls -l > test");
              catch (Exception e)
                   System.out.println("Error executing nedit.");
    }can anyone help please.

    get the the inputStream of the runtime object after executing the command.
    now use the readLine() function until it becomes null.
    egs: with reference to ur code.
    InputStream is=p.getInputStream()
    while(is!=null)
    String s=is.readLine();
    if the command don't execute try giving the full path also like /sbin/ls -l

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                          // any output?
              StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                          // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

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

  • Please help How can i run Os commands thru Java programs

    Hey,
    I want to stop and restart the linux server thru java program.Is it possible to run the os commands thru java program.
    I had it thru Runtime.getRuntime().exec("*.exe");
    it only runs the exe files.How can run files other than exe files like .bat,com ans shell commands..Any body knows please help with the code..or mail to this address
    [email protected]
    thankyou,
    regards,
    j.mouli

    What about "start command.com /C execute.bat", or using the overload that takes a String[] as argument?
    What if you use the the full path of execute.bat?
    What error code do you get?
    And what comes th linux, I'm not sure... you'll need a shell interpreter there too, me thinks. (never had to run anything with runtime.exec on linux). Check the man pages if csh, bash, ksh, or what ever shell you like.

  • Run Basic Command-line Java Programs in Sandvox

    Is it possible to put a command-line Java program on a website in Sandvox and make it run?

    See: documentation for designers

  • 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 do run unix command in java

    hi
    All unix command working fine in our java program.
    but i want change user in linux by using java. it's not working.
    "su root" This command onely not working.
    anybody know help me
    This is my ID [email protected]
    This my code
    <% String s = null;
    try{
    Process p = Runtime.getRuntime().exec("su root");
    BufferedReader stdInput = new BufferedReader(new
    InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new
    InputStreamReader(p.getErrorStream()));
    out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null)
    out.println(s);
    catch(Exception e) {}
    %>

    I don't have further info to add to your first post, but think your guess seems quite reasonable. I thought of starting a new thread on the same topic, but think this (question) fits in here, too.
    I have Java code (freeware, not opensoure), intended for Unix, which basically provides the graphical interface and relies on an I/O layer (C + shell scripts) to do most of the work. I have access to the C+shell scripts which are opensource. I ported it to Cygwin and want to use it under Windows (there is no Cygwin native Java VM).
    My problem now boils down to " how to run commands under Unix and what differences are there with Windows". What are the variants?
    I have to guess what the program is doing when I get an IOException at some point. E.g.: a call to shell script may be made in a different way as to a compiled exe in Unix?. I found a way to bypass path problems because forward slashes are also accepted and /cygdrive/c construct can be replace by c:/; shell scripts can be compiled into exes using shc and they work; if symbolic links are replaced by duplication of exe files, they work. What will happen in an instance whereby a process runs a shell script dynamically, through a pipe (the shell script is compiled in the Cygwin/win version and receives parameters) in a construct like:
    pipefp = epopen(cmdbuf,"w"); /* (cmbuf is "makehdr par1 par2 ... ") (makehdr was a shell script and is now compiled exe for Cygwin/Windows) */?.
    Thanks.
    LT

Maybe you are looking for

  • What is the value of sy-ucomm when tab is pressed

    Hi Experts, what is the value of sy-ucomm when tab is pressed or is there any way to detect or capture the pressing of  tab as we do for the enter. if so kindly help please advance thanks

  • How to get checkboxes in dynamic ALV list generation

    hi , below is the code in which two lists we wll be displayed in one layout dynamically(i.e after entering the table name two lists wll be displayed in one layout) from two different clients(i.e. source and target). TYPE-POOLS * TYPE-POOLS: slis. *--

  • Time management status  doubt

    Hi Friends, what is the difference between time management status 0 and 9. when we can use 0 and 9. Thanks in advance Venkat

  • Mocha in After Effects

    Hi, CS5 PP came with "mocha". CS6 did not. Is it possible to install CS5's mocha in CS6? Pieter

  • My ipod wont advance to the next song on its own

    When a song plays, it won't advance to the next song unless I manually click on the next song. I want to be able to have the whole album play without haveing to click on next songs. Thanks for your help