Java Shell

As part of my course (Computer Science), I have been asked to write a Unix shell in java. Unfortunately, I have only just started my course on programming in java, and have never used UNIX before, so am finding it quite hard.
I have got most of the program to work, although when I run a thread (with valid commands ie finger, who, clear etc.), I get the message "java.lang.ArrayIndexOutOfBoundsException" at UnixThread.run(UnixThread.java, compiled code).
I imagine the problem is that I am trying to run Unix commands from within the constraints of my program. The only way I can see to get around this is by creating some sort of batch file/script which loads when my shell quits, and then re-loads my shell as its last line. Unfortunately I do not know how to do this, and even if it did work, it would not allows background execution.
Any help would be appreciated
-=Jonny B=-

Hmm - I don't think that's the problem. Here's my code for the project - incase you can tell more from seeing the actual code in question.
cheers,
-=JB=-
/*project needs:
     jsh.java (this file)
     UnixThread.java
     EasyIn.java
//jsh.java:
import java.util.StringTokenizer;
class jsh{
     public static void main(String [] args){
          boolean exit = false;
          String command = "";
          while (exit==false){/*until user quits*/
               System.out.print("jsh> ");
               command = EasyIn.getString();
               while(command.indexOf(";;") > -1){/*removes any double ;'s which may cause errors*/
                    command = command.substring(0, (command.indexOf(";;")+1) ) + command.substring((command.indexOf(";;")+2), (command.length()+1));
               StringTokenizer commands = new StringTokenizer(command,";");
               UnixThread runThread = new UnixThread(commands.countTokens());
               while (commands.hasMoreTokens()) {
                    command = commands.nextToken();
                    if (command.equalsIgnoreCase("exit") && commands.hasMoreTokens()){
                         System.out.println("EXIT must be the final command in the thread. This command has been ignored.");
                         EasyIn.pause("Press a key to continue...");
                         System.out.println();
                    }else{
                         runThread.addCommand(command);
                    /*System.out.println(command);*/
               if (command.equalsIgnoreCase("exit")) {
                    exit = true;
               }else{
                    runThread.start();
//UnixThread.java
import java.io.*;
class UnixThread extends Thread{
     String[] allCommands;
     int commandNo = 0;
     UnixThread(int arraySize){ /*constructor used to initialise allCommands array to correct size*/
          allCommands = new String[arraySize];
     public void addCommand(String command){/*accessor method to add commands to the array*/
          allCommands[commandNo] = command;
          commandNo += 1;
     public void run(){/*executes the thread.*/
          Runtime go = Runtime.getRuntime();
          Process proc;
          for (int counter=0;counter < commandNo; counter++){
               try{
                    proc = go.exec(allCommands[counter]);
                    InputStreamReader fromScreen = new InputStreamReader(proc.getInputStream());
                    BufferedReader fromUnix = new BufferedReader(fromScreen);
                    if(allCommands[commandNo].charAt(allCommands[commandNo].length() - 1) != '&'){//if not background job
                         System.out.println(fromUnix.readLine());
               }catch(IOException error){
                    System.out.println("Bad command or Filename");
                    System.out.print("jsh> ");/*re-displays command prompt*/
// EasyIn.java
import java.io.*;
public abstract class EasyIn
static String s = new String();
static byte[] b = new byte[512];
static int bytesRead = 0;
public static String getString()
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
s=s.trim();
ok = true;
catch(IOException e)
System.out.println(e.getMessage());
     return s;
public static int getInt()
int i = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
i = Integer.parseInt(s.trim());
ok = true;
catch(NumberFormatException e)
System.out.println("Make sure you enter an integer");
catch(IOException e)
System.out.println(e.getMessage());
return i;
public static byte getByte()
byte i = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
i = Byte.parseByte(s.trim());
ok = true;
catch(NumberFormatException e)
System.out.println("Make sure you enter a byte");
catch(IOException e)
System.out.println(e.getMessage());
return i;
public static short getShort()
short i = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
i = Short.parseShort(s.trim());
ok = true;
catch(NumberFormatException e)
System.out.println("Make sure you enter a short integer");
catch(IOException e)
System.out.println(e.getMessage());
return i;
public static long getLong()
long l = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
l = Long.parseLong(s.trim());
ok = true;
catch(NumberFormatException e)
System.out.println("Make surre you enter a long integer");
catch(IOException e)
System.out.println(e.getMessage());
return l;
public static double getDouble()
double d = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
d = (Double.valueOf(s.trim())).doubleValue();
ok = true;
catch(NumberFormatException e)
System.out.println("Make sure you enter a decimal number");
catch(IOException e)
System.out.println(e.getMessage());
return d;
public static float getFloat()
float f = 0;
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
f = (Float.valueOf(s.trim())).floatValue();
ok = true;
catch(NumberFormatException e)
System.out.println("Make sure you enter a decimal number");
catch(IOException e)
System.out.println(e.getMessage());
     return f;
public static char getChar()
char c = ' ';
boolean ok = false;
while(!ok)
try
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
if(s.trim().length()!=1)
System.out.println("Make sure you enter a single character");
else
c = s.trim().charAt(0);
ok = true;
catch(IOException e)
System.out.println(e.getMessage());
return c;
public static void pause()
boolean ok = false;
while(!ok)
try
System.in.read(b);
ok = true;
catch(IOException e)
System.out.println(e.getMessage());
public static void pause(String messageIn)
boolean ok = false;
while(!ok)
try
System.out.print(messageIn);
System.in.read(b);
ok = true;
catch(IOException e)
System.out.println(e.getMessage());
}

Similar Messages

  • Rel 12 - How to create a new APPS connection from custom Java/Shell Script

    Hi,
    I am looking to write a custom JAVA code / Shell Script which needs to establish a connection to execute a PL/SQL API on Rel 12 db.
    The challenge is to be able to connect without specifying APPS Password anywhere (just like Oracle Apps does it).
    This Shell script / Java code is not called from within Apps hence I need to establish a brand new connection along the lines of using ....
    WebAppsContext ctx = new WebAppsContext(System.getProperty("JTFDBCFILE"));
    OracleConnection conn = (OracleConnection)ctx.getJDBCConnection();
    like in 11i world or possibly using APPLSYSPUB username
    I need help / direction in how to do this in a Rel 12 env. I understnad there are lot of architecture changes and if someone can provide a generic code snipped it will be great.
    I need to keep this as closely aligned to Rel 12 coding and security standards as possible.
    This code will reside in $XXCUSTOM_TOP/bin file or under XXCUSTOM.oracle.apps.java....... if its Java.
    Pls help.
    Cheers
    -- VK.

    Hi,
    Have you looked at Oracle produced dbc file and its contents? That might help. It is under $FND_TOP/secure. It uses GWYUID=APPLSYSPUB/PUB. I am hoping that the APPS_JDBC_URL would help too.
    Regards,

  • Run java shell script on Linux

    Hi I am just trying to convert a Windows batch file to a unix shell script to run a java application, but it so long since Ive used UNIX I cant really remember how to do it.
    My script contains
    #!/bin/sh
    java  -jar lib/testapp.jarThese are my failed attempts to run it, not too sure what the differences are but I think the 3rd one is the only one to actually find my shell script.
    [root@]# testapp.sh
    -bash:  testapp.sh: command not found
    [root@]# ./ testapp.sh
    : bad interpreter: No such file or directory
    [root@]# .  testapp.sh
    Unable to access jarfile lib/testapp.jarif I just do this at the command line it works fine
    [root@]#java  -jar lib/testapp.jar

    #1
    [root@]# testapp.sh
    -bash:  testapp.sh: command not found
    #2
    [root@]# ./ testapp.sh
    : bad interpreter: No such file or directory
    #3
    [root@]# .  testapp.sh
    Unable to access jarfile lib/testapp.jar#1 is because the command (testapp.sh) is not found on the PATH. Under Unix the current directory . is not included automatically in the PATH: it has to be excplicitly specified, and this is a good thing. Also make sure it has the x (executable) switch on: chmod +x  testapp.sh
    #2 is because you had an extra space in what should have been
    ./testapp.sh #3 there you could "inline" the script but the file lib/testapp.jar was appearently not found. Is lib really under the working directory or in other some place?

  • Executing native library under Java - shell script problem

    I am running a Java application on the command line bash shell. I have a few JAR files in the directory and a few native libraries. When I run the application using the command line, all works fine. This is the command I use:
    java -classpath MyGame.jar:log4j-1.2.16.jar:jme/jme-colladabinding.jar:jme-audio.jar:jme-awt.jar:jme-collada.jar:jme-editors.jar:jme-effects.jar:jme-font.jar:jme-gamestates.jar:jme-model.jar:jme-ogrexml.jar:jme-scene.jar:jme-swt.jar:jme-terrain.jar:jme.jar:jogl/gluegen-rt.jar:jogl/jogl.jar:jorbis/jorbis-0.0.17.jar:junit/junit-4.1.jar:lwjgl/jinput.jar:lwjgl/lwjgl.jar:lwjgl/lwjgl_util.jar:lwjgl/lwjgl_util_applet.jar:swt/windows/swt.jar:jbullet/jbullet-jme.jar:jbullet/asm-all-3.1.jar:jbullet/jbullet.jar:jbullet/stack-alloc.jar:jbullet/vecmath.jar:trove-2.1.0.jar:sceneMonitor/jmejtree_jme2.jar:sceneMonitor/propertytable.jar:sceneMonitor/scenemonitor_jme2.jar:sceneMonitor/sm_properties_jme2.jar -Djava.library.path="lwjgl/native/linux" -Xmx1024m -Xms768m -ea com.mygame.MainThis works fine and the application starts up as expected. LWJGL native library is loaded in and works fine as expected.
    The problem occurs when I try to run this command via the shell using a shell script. Here is my script:
    #!/bin/bash
    # Set the minimum and maximum heap sizes
    MINIMUM_HEAP_SIZE=768m
    MAXIMUM_HEAP_SIZE=1024m
    if [ "$MYAPP_JAVA_HOME" = "" ] ; then
        MYAPP_JAVA_HOME=$JAVA_HOME
    fi
    _JAVA_EXEC="java"
    if [ "$MYAPP_JAVA_HOME" != "" ] ; then
        _TMP="$MYAPP_JAVA_HOME/bin/java"
        if [ -f "$_TMP" ] ; then
            if [ -x "$_TMP" ] ; then
                _JAVA_EXEC="$_TMP"
            else
                echo "Warning: $_TMP is not executable"
            fi
        else
            echo "Warning: $_TMP does not exist"
        fi
    fi
    if ! which "$_JAVA_EXEC" >/dev/null ; then
        echo "Error: No Java environment found"
        exit 1
    fi
    _MYAPP_CLASSPATH="MyGame.jar:log4j-1.2.16.jar:jme/jme-colladabinding.jar:jme-audio.jar:jme-awt.jar:jme-collada.jar:jme-editors.jar:jme-effects.jar:jme-font.jar:jme-gamestates.jar:jme-model.jar:jme-ogrexml.jar:jme-scene.jar:jme-swt.jar:jme-terrain.jar:jme.jar:jogl/gluegen-rt.jar:jogl/jogl.jar:jorbis/jorbis-0.0.17.jar:junit/junit-4.1.jar:lwjgl/jinput.jar:lwjgl/lwjgl.jar:lwjgl/lwjgl_util.jar:lwjgl/lwjgl_util_applet.jar:swt/windows/swt.jar:jbullet/jbullet-jme.jar:jbullet/asm-all-3.1.jar:jbullet/jbullet.jar:jbullet/stack-alloc.jar:jbullet/vecmath.jar:trove-2.1.0.jar:sceneMonitor/jmejtree_jme2.jar:sceneMonitor/propertytable.jar:sceneMonitor/scenemonitor_jme2.jar:sceneMonitor/sm_properties_jme2.jar"
    _VM_PROPERTIES="-Djava.library.path=\'lwjgl/native/linux\'"
    _MYAPP_MAIN_CLASS="com.mygame.Main"
    $_JAVA_EXEC -classpath $_MYAPP_CLASSPATH $_VM_PROPERTIES -Xmx${MAXIMUM_HEAP_SIZE} -Xms${MINIMUM_HEAP_SIZE} -ea $_MYAPP_MAIN_CLASSThe shell script is in the same directory as the JAR files (the same directory where I ran the Java command above). When I execute the shell script ( sh MyGame.sh ), I get the UnsatisfiedLinkError message:
        14-Feb-2011 19:46:28 com.wcg.game.DefaultUncaughtExceptionHandler uncaughtException
        SEVERE: Main game loop broken by uncaught exception
        java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
           at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
           at java.lang.Runtime.loadLibrary0(Runtime.java:823)
           at java.lang.System.loadLibrary(System.java:1028)
           at org.lwjgl.Sys$1.run(Sys.java:73)
           at java.security.AccessController.doPrivileged(Native Method)
           at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
           at org.lwjgl.Sys.loadLibrary(Sys.java:82)
           at org.lwjgl.Sys.<clinit>(Sys.java:99)
           at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
           at com.jme.system.lwjgl.LWJGLDisplaySystem.setTitle(LWJGLDisplaySystem.java:118)
           at com.wcg.game.WcgStandardGame.initSystem(WcgStandardGame.java:287)
           at com.wcg.game.WcgStandardGame.run(WcgStandardGame.java:185)
           at java.lang.Thread.run(Thread.java:662)I don't understand what I am doing wrong. I am executing the exact same command via a shell script and it is not working. Any ideas, solutions, most welcome.
    I am running Linux Mint Debian 201012, Linux mint 2.6.32-5-amd64 #1 SMP Thu Nov 25 18:02:11 UTC 2010 x86_64 GNU/Linux. JDK is 1.6.0_22 64-bit. I have 64-bit .so files in the correct place too.
    Thanks
    Riz

    Thanks for the replies guys/gals.
    I have modified the script and echoed my command that should be running under the shell script, it is:
    java -classpath WcgFramework.jar:WcgPocSwordplay.jar:log4j-1.2.16.jar:jme/jme-colladabinding.jar:jme-audio.jar:jme-awt.jar:jme-collada.jar:jme-editors.jar:jme-effects.jar:jme-font.jar:jme-gamestates.jar:jme-model.jar:jme-ogrexml.jar:jme-scene.jar:jme-swt.jar:jme-terrain.jar:jme.jar:jogl/gluegen-rt.jar:jogl/jogl.jar:jorbis/jorbis-0.0.17.jar:junit/junit-4.1.jar:lwjgl/jinput.jar:lwjgl/lwjgl.jar:lwjgl/lwjgl_util.jar:lwjgl/lwjgl_util_applet.jar:swt/windows/swt.jar:jbullet/jbullet-jme.jar:jbullet/asm-all-3.1.jar:jbullet/jbullet.jar:jbullet/stack-alloc.jar:jbullet/vecmath.jar:trove-2.1.0.jar:sceneMonitor/jmejtree_jme2.jar:sceneMonitor/propertytable.jar:sceneMonitor/scenemonitor_jme2.jar:sceneMonitor/sm_properties_jme2.jar -Djava.library.path="lwjgl/native/linux" -Xmx1024m -Xms768m -ea com.mygame.MainI am more confident that now the shell script should be fine (I am a shell script noob) because this very command if I copy from terminal and paste into the terminal, runs the application no problem at all. But I am amazed that it is still not working. I must be doing something obviously wrong. :-(
    I used the code as suggested:
    _VM_PROPERTIES='-Djava.library.path="lwjgl/native/linux"'I am stumped!? :-(
    Thanks for help.

  • How to execute programs by java (shell excecute)

    i need to know how to execute a prog or a system call by java and pass tp it an argument

    Hi, look at the java.lang.Runtime class.
    eg Runtime.getRuntime().exec(<command>, <arguments>);
    ;) Patrick

  • Java 6 Shell Archive?

    In support of my configuration I need to locate the latest Java 6 release of the JDK and JRE specifically in the Java Shell Archive format. Can you please point in the right direction as to where I can find this?
    Thanks.

    If you follow Pascal's or mine link before you end up:
    http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR
    and after accepting the license agreement you could download the following:
    Solaris x64: http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-solaris-i586.sh
    Solaris x86: http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-solaris-x64.sh
    Solaris SPARC-32: http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-solaris-sparc.sh
    Solaris SPARC-64: http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-solaris-sparcv9.sh
    Hope this helps.
    Marco
    P.S.: if that answer your question, please remember to flag all the helpful/correct answers to close the thread and make it easier for the others finding this information

  • Displaying a shell from within a Java program

    Hi,
    For some long and twisted reason, I need to execute native programs from a Java program. Since this program is only every intended to be run on Linux, this doesn't bother me breaking the x-platform rules for Java! So, Runtime.exec() is the normal way to do this.
    However, Runtime.exec() runs executes the command and then dishes basck the output once it's finished. The external program I wish to run takes a while and actually prints various pieces of feedback during its processing. I'd like to display this feedback to the user as it happens, rather than dumping it all at the end.
    I can't think of anyway to do this. I've been looking for "Java shells" but they are reimplemented shells with only let you run classes on the classpath. Any ideas from the gurus around here?
    Cheers

    import java.util.*;
    import java.io.*;
    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);
    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 GoodLinuxExec
    public static void main(String args[])
    if (args.length < 1)
    System.out.println("USAGE: java GoodLinuxExec <cmd>");
    System.exit(1);
    try
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + args[0]);
    Process proc = rt.exec(args);
    // 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();
    stolen from this article and adapted to suit an os which does not start with the letter W.

  • JACL, TCLBlend, TCL Shell, JAVA Interface

    My goal: To embed a TCL Shell Interpreter into my JAVA program so I can source tcl files and run procs.
    Tools available to me that I know of: JACL and TCLBlend.
    I have been trying to use JACL since it's pure Java based as opposed to TCLBlend. I am using version JACL 1.0.
    I found a TCL Shell code example and I'm trying to make it work. I appended it at the end of my note.
    It compiles fine, but when I run it, I get this output:
    ==============================
    missing close-brace
    tcl.lang.TclException
         at tcl.lang.Parser.eval2(Parser.java)
         at tcl.lang.Interp.eval(Interp.java)
         at tcl.lang.Interp.evalResource(Interp.java)
         at tcl.lang.Interp.<init>(Interp.java)
         at TCL.Shell.main(Shell.java:54)
    tcl.lang.TclRuntimeError: unexpected TclException: tcl.lang.TclException
         at tcl.lang.Interp.<init>(Interp.java)
         at TCL.Shell.main(Shell.java:54)
    Exception in thread "main" Process Exit...
    =======================
    I was reading about this error and I think it has something to do with either the 'set TCL_LIBRARY=" settingi nthe autoexec or the \ esc char in the init.tcl file.
    I have added this line to my autoexec:
    set TCL_LIBRARY=C:\jdk\Jacl1.0\src\java\tcl\lang\library
    I also tried deleting some of the \ esc chars. I might try doubling them up next.
    I don't know what to do to make this code work?
    ====================
    package TCL;
    * Shell.java --
    * Implements the start up shell for Tcl.
    * Copyright (c) 1997 Cornell University.
    * Copyright (c) 1997 Sun Microsystems, Inc.
    * See the file "license.terms" for information on usage and
    * redistribution of this file, and for a DISCLAIMER OF ALL
    * WARRANTIES.
    import java.util.*;
    import java.io.*;
    import tcl.lang.*;
    * The Shell class is similar to the Tclsh program: you can use it to
    * execute a Tcl script or enter Tcl command interactively at the
    * command prompt. This implementation uses only the classes provided
    * by the Jacl or TclBlend distribution.
    * To use this class with Jacl, put "tcljava.jar" and "jacl.jar" in
    * the CLASSPATH. To use this class with TclBlend, put "tcljava.jar" and
    * "tclblend.jar" in the CLASSPATH. Compile this class by:
    * javac -classpath $CLASSPATH Shell.java
    * Run this class by:
    * java -classpath $CLASSPATH Shell
    * When using this class with TclBlend on UNIX, also make sure that the
    * "libtclblend.so" and "libtclxx.so" are in your LD_LIBRARY_PATH. When
    * using this class with TclBlend on Windows, make sure that the
    * "tclblend.dll" and "tclxx.dll" are in your PATH. Also make sure that
    * the environment variable "TCL_LIBRARY" is set to point to the library
    * for Tcl 8.2. The TCL_LIBRARY environment variable must be set.
    public class Shell {
    * main -- Main program for tclsh and most other Tcl-based applications.
    public static void main (String args[])
    // Create the interpreter. This makes the main thread the
    // Tcl interpreter thread.
    Interp interp = new Interp();
    // Process command line arguments, ignored for simplicity.
    // Start the ConsoleThread that loops, grabbing stdin and passing
    // it to the interp.
    ConsoleThread consoleThread = new ConsoleThread(interp);
    consoleThread.setDaemon(true);
    consoleThread.start();
    // Loop forever to handle user input events in the command line.
    Notifier notifier = interp.getNotifier();
    while (true) {
    // Process events until the user types "exit".
    notifier.doOneEvent(TCL.ALL_EVENTS);
    } // end class Shell
    * ConsoleThread -- This class implements the Console Thread: The console
    * thread loops forever, reading from the standard input, executing the user
    * input and writing the result to the standard output.
    class ConsoleThread extends Thread {
    * Interpreter associated with this console thread.
    private Interp interp;
    * Collect the user input in this buffer until it forms a
    * complete Tcl command.
    private StringBuffer sbuf;
    * ConsoleThread -- Create a ConsoleThread.
    ConsoleThread(Interp i) // Reference to the interp object.
    setName("ConsoleThread");
    interp = i;
    sbuf = new StringBuffer(100);
    * run -- Called by the JVM to start the execution of the
    * console thread. It loops forever to handle user inputs.
    public void run()
    put(System.out, "% "); // put up a prompt
    while (true) {
    // Loop forever to collect user inputs in a StringBuffer.
    // When we have a complete command, then execute it and print
    // out the results.
    // The loop is broken under two conditions: (1) when EOF is
    // received inside getLine(). (2) when the "exit" command is
    // executed in the script.
    getLine();
    // We have a complete or partial command now. Execute it.
    // We use a ConsoleEvent to make the interpreter thread
    // executing the command instead of executing the command
    // directly here.
    ConsoleEvent evt = new ConsoleEvent(this);
    interp.getNotifier().queueEvent(evt, TCL.QUEUE_TAIL);
    evt.sync(); // wait for the Interp to finish handling the
    // command
    * safeEvalCommand -- Called by the ConsoleEvent.processEvent.
    * This method should only be called from the processEvent() method
    * of the ConsoleEvent The ConsoleEvent.processEvent() method is
    * guaranteed to be called by the TCL interpreter thread. As a
    * result, it is safe to access Interp class data and method inside
    * this method.
    void safeEvalCommand()
    String command = sbuf.toString();
    if (Interp.commandComplete(command)) {
    try {
    // we have a complete Tcl command, call the interpreter
    // method to execute the Tcl command
    //interp.recordAndEval(TclString.newInstance(command), 0);
              interp.eval(TclString.newInstance(command), 0);
    TclObject evalResult = interp.getResult();
    evalResult.preserve();
    String s = evalResult.toString();
    if (s.length() > 0) {
    putLine(System.out, s);
    evalResult.release();
    } catch (TclException e) {
    // Execution of the Tcl command caused an error
    int code = e.getCompletionCode();
    check_code: {
    if (code == TCL.RETURN) {
    //code = interp.updateReturnInfo();
    //if (code == TCL.OK) {
    // break check_code;
    switch (code) {
    case TCL.ERROR:
    putLine(System.err, interp.getResult().toString());
    break;
    case TCL.BREAK:
    putLine(System.err,
    "invoked \"break\" outside of a loop");
    break;
    case TCL.CONTINUE:
    putLine(System.err,
    "invoked \"continue\" outside of a loop");
    break;
    default:
    putLine(System.err,
    "command returned bad code: " + code);
    sbuf.setLength(0); // empty the input buffer
    put(System.out, "% "); // put a command prompt
    } else {
    // We don't have a complete command yet. Print out a level 2
    // prompt message and wait for further inputs.
    put(System.out, " ");
    * getLine -- Gets a new line from System.in and put it in sbuf.
    private void getLine() {
    int availableBytes = -1;
    // Loop until user presses return or EOF is reached.
    char c2 = ' ';
    char c = ' ';
    while (availableBytes != 0) {
    try {
    int i = System.in.read();
    if (i == -1) {
    if (sbuf.length() == 0) {
    System.exit(0);
    } else {
    return;
    c = (char) i;
    availableBytes--;
    if (c == '\r') {
    i = System.in.read();
    if (i == -1) {
    if (sbuf.length() == 0) {
    System.exit(0);
    } else {
    return;
    c2 = (char) i;
    if (c2 == '\n') {
    c = c2;
    } else {
    sbuf.append(c);
    c = c2;
    } catch (IOException e) {
    // IOException shouldn't happen when reading from
    // System.in. The only exceptional state is the EOF event,
    // which is indicated by a return value of -1.
    e.printStackTrace();
    System.exit(0);
    sbuf.append(c);
    if (c == '\n') {
    return;
    * putLine -- Prints a string into the given channel with a trailing
    * carriage return.
    private void putLine (PrintStream chan, // The channel to print to.
    String s) // The string to print.
    chan.println(s);
    chan.flush();
    * put -- Prints a string into the given channel without a trailing
    * carriage return.
    private void put (PrintStream chan, // The channel to print to.
    String s) // The string to print.
    chan.print(s);
    chan.flush();
    } // end of class ConsoleThread
    * This class is used by the ConsoleThread to post a Tcl Event to the
    * Tcl interpreter's event queue. The processEvent method of this class
    * is then executed by the Tcl interpreter's event thread to call
    * the interpreter's method safely.
    class ConsoleEvent extends TclEvent {
    * The ConsoleThread that issued this event
    private ConsoleThread console;
    * ConsoleEvent -- Creates a new ConsoleEvent instance.
    ConsoleEvent(ConsoleThread consoleThread) // The thread that issued
    // this event
    console = consoleThread;
    * processEvent -- Process the console event. This method may freely call
    * any Tcl interpreter's method. It is safe.
    public int processEvent(int flags)
    console.safeEvalCommand(); // calls the console thread's method to
    // do the actual work
    return 1;
    } // end of ConsoleEvent

    Im not sure actually. Its some time since I used it. But if im not wrong it was included in the download at www.scriptics.com... I just checked http://sourceforge.net/projects/tcljava/ but there dosnt seem to be any downloads... only source.
    By the way - what are u going to use it for... Its a nice idea to attach a shell to some java prog. I could use some scripting ability with my current project. But I really hate the tcl syntax for java commands. I would prefer some java-shell with java syntax. Besides, going through tcl to execute java-statements seems stupid. Have u heard of something like a java-shell? Wondering if it would be possible to do it through reflextion. But guess ur more interested in running tcl scripts through ur java code. (but u dont need that shell interface for that, eg. ur code example).
    Stig.

  • Java Error While Running Upgrade Assistant

    Hi,
    We are in process of upgrading SAP from 4.7 EX 2 to ECC 6.0 in I5/V6R1M0 on
    AS400.When running the statup of the UA server we are running into error saying
    that" Unable to start Java shell, reason code 3006". Any Idea what could be the problem.
    Regards!
    Ravi

    Hi Ravi,
    The variables mentioned in my first reply should be sufficient for determination of your profile's location and name. The resulting string is what you see:
    /usr/sap/<SID>/SYS/profile/<SID>_*NULL_<server_name>."
    lets me assume that
    SAPSYSTEMNAME is set to <SID>
    INSTANCE_NAME is not set at all
    and most probably
    SAPLOCALHOST is set to <server_name>
    Can you verify that the values are meaningfull (real SID, something like DVEBMGS00, real server name) before you call command UASERVER?
    Regards,
    Thomas

  • Problem while spawning scp (secure copy) in Java

    Hi,
    We are calling shell script to spawn scp (secure copy) in Java. JVM version is 1.4.2. While trying to invoke this shell script on JVM 1.4.2 in UNIX environment, it doesnot give desired result. Either it gives the error as :
    1)
    "The authenticity of host 'sxfer01.bluecrossmn.com (159.136.224.30)' can't be established.
    RSA key fingerprint is 8d:84:82:c2:bb:15:94:e1:30:e1:11:0e:3f:8b:83:24.
    Are you sure you want to continue connecting (yes/no)?"
    After saying "yes", it hangs.
    OR
    2) It doesnot display the value for output variables. Value will be blank and it goes back to system prompt. It doesnot hang.
    So How to treat scp utility in JVM 1.4.2? Any change / configuration to be done ?
    Thanks,
    Asawari

    As a guess....
    1. You first need to understand how to run the command successfully from a command prompt.
    2. Again from the command prompt you then need to understand what sort of errors the command can generate and what action you need to take based on those errors.
    3. You need to create (ONLY after 1 and 2 are complete) a command line simulator which MUST use threads in java. Your simulator knows how to correctly accept all possible responses from the command and how to respond to them. (And you better understand how java shells out commands and handles streams for them as well.)

  • Integrate Java standalone application when WIndows start

    Hello everybody.I would like to ask you if it is possible to load a Java standalone application when any Windows platform (NT/2000/98/XP) starts.
    How can I integrate an application when WIndows start?Do I have to include the bat file(which callls the java applictaion) into a Windows system file?
    Regards.

    You can do one of several things:
    1. Write a native executable that runs the Java Archive (JAR) using the java shell command.
    2. Write a Windows shortcut that runs the java shell command (again passing in the JAR).
    3. Purchase software that will produce a native executable that will run the JAR for you.
    4. Integrate JAR files as executable programs into your Kernel. In Windows this is not easy, but again, there are solutions on the Internet, but you will most likely have to purchase these.
    5. Configure the JAR file type so that when any JAR file type is double-clicked (and the default action is performed), the Java runtime is executed with the JAR as a parameter.
    5 is my usual solution, and for operating systems like Linux, and especially MacOS, it is much easier to get JARs to run 'more natively'.
    The answer to your question is simply 'Yes' but it is your choice of how to do this.
    As far as running the JAR when your desktop starts up (Explorer in this case), you can do two things - firstly there's a 'Run' item in your registery where you can place the location of your shortcut / executable, secondly, you can simply put the short-cut or the executable (I recommend a shortcut) in your 'Startup' folder of your Start Menu. (Start -> Programs -> Startup).
    I hope this helps.
    Gen.
    http://www.opetec.com/

  • Ilash shell question -- where is it????

    I am running Sun ONE Directory Server v5.2. I have just installed the resourse kik, dsrk5.2.
    I want to run the program called ilash. If I understand the documents correctly, ilash is a command shell into the directory server.
    My first problem is: I cant find the shell. I have looked in the usual places (/var/mps, /usr/ds, and the directories created by the by the dsrk install process) and I cant find it.
    Maybe my question should be how do I start the shell. It could be something like jave <shell name>. In any case, any help is appreciated.
    My second problem, or question, is: does anyone have an example of a system.lashconfig and/or a .lashconfig file?
    Actually a .lashrc file example would be nice also.
    Any advise is appreciated.
    Thanks,
    massiedh88

    ilash is no longer part of the Directory Server Resource Kit, and will not be available from Sun.
    I believe it has something to do with some licensing issues that prevent us from supporting it.
    Ludovic.

  • Insert a record into a table through email in an Oracle APEX application

    I developed an Oracle APEX application, there is a table called events. I can insert/update/delete a record in the table through browser. I am thinking in order to quickly do the data entry, user should be able to send an email, then the table should be inserted with values from email address, timestamp, subject and body. Anyd idea how to realize this functionality?
    - Denis

    Start by checking whether your mail server provides any API's for accessing emails , if it does you might be able to reduce a lot of work by using some kind of web service consumer from apex to your mail server. In any case your implementation is going to be dependent on your Mail Server configuration.
    Your problem breaks down to reading/accessing mails from the mail server from PLSQL (apex is driven by PLSQL).
    I found this other thread which could be of some use.
    WAY TO ACCESS A MAIL SERVER FROM ORACLE APEX
    <li>The following package might solve your problem directly(from carsten czarski of the German Apex community)
    [url http://plsqlmailclient.sourceforge.net]http://plsqlmailclient.sourceforge.net
    PS: POP3 support is still TBD.
    <li>I also found this posting in the orafaq forums which lists a java method and PLSQL code bit for it for accessing emails via POP3
    [url http://www.orafaq.com/forum/t/80928/2/]http://www.orafaq.com/forum/t/80928/2/
    If these do not work for you, find some java library to read mail from your server, write a PLSQL wrapper for it and use it in a scheduled job(DBMS_JOB)/a PLSQL block triggered from Apex.
    If you get stuck there, find some utility that can read mails, invoke them from your DB using java,shell scrpt,dbms_scheduler etc and use the utility's function for the rest.
    NOTE: I haven't tried any of these utilities and you must validate any java code before running them on your environment.
    Since aren't really much restrictions(other than spam checks) in sending a mail to your mail account, you might want to consider filtering out the mails from which you create records.

  • Career path

    Hi all,
    I'm a junior-mid level Java programmer (2.5 year of Java developing). Worked mostly on backend server side using core Java, haven't actually worked on J2EE (servlets, JSP, EJB, ...)
    I need to look for a new opportunity as the company I'm working in started to offshore the development. I came across many opportunities, however, am very confused what's the best thing to do, and the path to take...
    I'm very interested in doing the server-side back end development (and prefer not to do gui, front end, swing, web design...)
    Since I like Java technologies, I look for Java developing positions; however I came across an opportunity that uses C# and Windows technologies and are interested to hire me and let me learn the technology and work on that. I am confused that if it's the right thing to do? I prefer Java and am interested to continue working on Java and become a senior-expert developer; I think if I continue working on Java then in the years to come I have like 5-6 years of Java and with knowing Java in much more details, will be able to do much more compare to know some Java and some C#, ... however, I look at people with 10 or more years of experience and see they did zillion things in their lives! They worked on C, C++, Java, shell scripting, C#, VB, HTML, ...
    So I taught maybe it's a wrong thing that I insist on Java only?
    What I've seen so far, is lots of opportunites asking for J2EE especially servelts and JSP (only a few give sb. like me a chance to learn and work at the same time!) I didn't follow a lot of them b/c don't want to end up doing JSP and web designing).
    So for what I prefer to do which is Java server side, back end development, using core Java or J2EE (especially if its new development rather than maintaing the existing code), what's the best path to take? My goal is to become an expert developer that writes his own code rather than maintaining other people's codes, what's the best way to reach my goal? I know it's a personal decision, but I'm confused now and appreciate any feedback and advice.

    Don't use just one language. You won't learn as much in general, and you won't even learn that one language very well. Other languages give you insights into programming that you can apply to the first language.
    No single language is perfect for everything. No single language is the best choice even for the tasks you'll need to perform in a single job. Use the best tool for the job. Learn different languages so you'll know about more tools.
    And you won't be well-respected by hiring managers if you only know one language.
    So, yes, you're wrong if you insist on Java only.
    If you want to write your own code, do so. Do your own projects and write code from scratch. As you get more confident, you'll be able to write code from scratch at work. Actually I'm surprised that you managed to get a job without being able to write programs from scratch.

  • Redirect output to jsh

    Hi there!
    I am working on a simple java shell in Windows XP at the moment which simply parses an entered command and passes it to ProcessBuilder as a list.
    It works ok - the process startsas expected - the only problem is I cannot see any output from the processes, nor can I figure out a way to redirect STDOUT to the running java shell from XP (which is what I really want).
    Here is my code so far - as I said, it's fairly basic at the moment.
    public class shell {
         public void start()throws java.io.IOException {
              String commandLine;
              BufferedReader console = new BufferedReader
              (new InputStreamReader(System.in));
              while(true)  {
                   System.out.print("jsh>");
                   commandLine = console.readLine();
                   if(commandLine.equals(""))
                        continue;
                   else process(commandLine);
                        continue;
         private void process(String cmd)
              String command = cmd;
              String[] commsplit = command.split("\\s");
              ProcessBuilder pb = new ProcessBuilder(Arrays.asList(commsplit));
              try {
              pb.start();
              catch (IOException ioe) {
                   System.err.println("Unknown command or input. Please try again");
         public static void main(String[] args)throws java.io.IOException {
              shell shell1 = new shell();
              shell1.start();
    }Any pointers in the right direction would be most appreciated.

    You need to process the stdout and stderr of the Process. This http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html shows you how to do it safely!

Maybe you are looking for