Spawn Unix Process in same shell with Java

Hello,
Does anyone know how to use java to prompt the user for input, execute their command, wait for the command to finish and then prompt them again.
I am able to prompt the user for input, but if they type 'vi filename' and I execute it, the user never sees the vi screen to edit the file. I would like to be able to allow other programs like 'vi' to use the same command line terminal that the user is currently in with java. Currently executing any command is fine, and I can read the process i/o. The only problem is when a program like 'vi' needs the terminal. Does java prevent that from happening when spawning a process?
Thanks,
Rick

Should this be command line based? There are several graphical java terminal emulators, here's an open source one for instance:
http://javassh.org/wiki-view?oid=5F8180808080808080808080808086neotis

Similar Messages

  • How to run sscript shell with java program

    Hi everybody,
    i want to know how can i do to execute a script shelle (bash) with program java (if it s possible)
    for example this script:
    #!/bin/bash
    echo "hello"
    can i run it with java program or i have to make dome modifications .
    thank you for your help in advance.

    Well, if you want to be portable across platforms, you should write as much code in Java as possible and not rely on native scripts (I'm sure your script is more complex than this 'echo' example ;-) ).
    Having said that, you can use the java.lang.Runtime class and in particular its various exec() methods.
    Try something like this:
    Process p;
    try {
        p = Runtime.getRuntime().exec("myscript.sh");
    } catch (IOException ioe) {
    }You can then "interact" with the spawned process with the Process object returned by the exec method.
    Note you need to have the appropriate security rights.
    For more details, look at the API documentation here:
    http://java.sun.com/j2se/1.4.2/docs/api/
    hth,
    -Alexis

  • C++ can send a "struct" over TCP.How to do the same fuction with JAVA?

    as Title~
    C++ send a struct like the following...
    NEO_MSG neo_msg;
    struct NEO_MSG
    int iPortRecv; // port for recv data of client
    char verify;
    ////After create a TCP connection....
    send(ServerSock, (char*)&neo_msg, sizeof(neo_msg), 0);
    How to rewrite it with JAVA?

    If you are trying to do it in a way that is compatible with C++, then you'll need to write the bytes to the socket. You can do this by wrapping the socket's output stream with a DataOutputStream, then writing each value in order.
    Remember that a C++ struct is just a convention of accessing a linear array of bytes, so the above is equivalent.
    If you are just trying to send an Object's data over a socket (to another Java app), then you can wrap the socket's output stream with an ObjectOutputStream, then just write the object to it.
    - K

  • OSX 10.4.10, Net beans and Sams Programing with JAVA

    I am brand new to Java so I downloaded Net Beans on my MAC. I bought a copy of Teach Your Self Programing with Java in 24 hrs.
    So far I got the first three programs to compile on Net Beans but got stuck when they started to talk about arguments. The following will not compile. Starting at line 2
    1) System.out.println("The " + arguments [0]
    2) + " " + arguments[1] + " fox "
    3) + "jumped over the "
    4) + arguments[2] + " dog. ")
    I get the little red x on each line.
    Is the book wrong or am I missing something?
    All the tutorials talk about Javac. I can't seem to find it or get to it on my computer. How do I know if I even have it?
    And is there such a thing as a "command line" on a MAC?

    Hi, you should put any code you post in between code brackets like this:
      code here   I dont use a mac or netbeans but javac is the java compiler, you would not have been able to compile the first two. The .exe (or whatever mac executable is) is usually located in the lib folder in the java directory. It comes when you download JDK. As for the code, it would help me if you posted the first couple lines of the error message. It looks fine to me, but I would need to see your whole class in order to help you further
    and yes there is a command line on a mac...i think its called terminal and usually looks like a little computer
    Edited by: jaredL on Sep 20, 2007 7:45 PM
    Edited by: jaredL on Sep 20, 2007 7:47 PM

  • View 2 Processes at same time with Lookout 6.1 Web Player

    In IE7 I am trying to view two process files at the same time. I have a tab for one process and a tab for the other, but I can only view one at a time. If I am looking at the process file that is on "tab 1" then all I get is a white screen on "tab 2". If I refresh "tab 2" then the process file under this tab opens and the process file on "tab 1" goes to a white screen.
    Is there a way to view both files at the same time?
    Jason Phillips

    I see the same behaviour. I guess you cannot. As Lookout can only run one instance, Lookout player also allows one instance running. So, if you refresh one, you see another stopped.
    Ryan Shi
    National Instruments

  • Should we avoid Graphical mapping and stick with Java mapping?

    After developing mappings in XI for a month, I just don't see any good reasons to use Graphical mappings over Java mappings. Maybe some experienced users here can give me some valid reasons why we should choose Graphical mappings. Here is what I think:
    Disadvantages of Graphical mappings:
    1. No way to perform automated unit testings. This is probably the biggest reason I hate it. You can do some tests manually when you work in Integration Builder. But there is no way you can write some unit testing utilities to automate the task.
    2. Complexity. Even for some simple requirements, your Graphical mappings can become complicated and hard to understand. A lot of times, I find myself staring at several dozens of graphical nodes and try to understand what it does.
    3. Impossible to reuse. This is totally against the DRY (Don't repeat yourself) principle. For example, to generate messages for JDBC adapter, it is common to have two identical fields for primary keys: one in the access node and another in the key node. If you change the mapping logic in one, you have to remember to change the other.
    Advantage with Java mappings:
    1. Fully automated unit testing. You can create JUnit tests along with your Java mapping classes and use Maven or other build tools to perform automated unit testing.
    2. Your choice of XML parsing and binding. With Java mapping, you can choose any open source framework for XML parsing and binding. For example, with XMLBeans, I can convert XML input message to a Java object, transform to another Java object and write to output message. And each Java object is generated from its corresponding XML schema.
    3. Highly reusable. We can use fundamental object-oriented designs to create highly reusable mapping components.
    4. Better version control. Since the mappings are just Java classes, we can use CVS or SVN to track code changes.
    5. Better build tools. We can fully utilize build tools like Ant and Maven to automate the build, unit tests, or even generate documents and mapping web sites.
    So do you guys agree? Maybe I am still new to XI or I am missing some important things. But at this point, I just don't see why I should use Graphical mappings. Is there anyone developing XI interfaces completely with Java mappings?
    Thanks in advance for any comments!
    Kenny Cheang

    Hi Suraj,
    > Since its graphical the blocks will take space, but
    > there is always an adavntage of processing time.
    > Ebven though it may appear bigger, it will take less
    > time as compared with Java code (for the same
    > mapping).
    Could you explain more why the graphical mapping has better performance? I thought the graphical mapping is compiled into a Java class in the runtime anyway.
    > Yes thats there, but same goes with Java mapping too
    > right (if you haven't mentioned it as constants)
    I mainly think about inheritance. If I have to build 10 interfaces and they all have some common behavior, I can create a base interface class to encapsulate the common logic. But with graphical mapping, you have to duplicate them in each interface.
    > Disadvantages of Java mapping:
    > 1. Performance
    Same as above. I just don't see why Java has worse performance. I actually think Java should have better performance. You can optimize the code anyway you want. In some cases, you have to use queue functions in graphical mapping but it's not necessary in Java.
    > 2. All might not be well versed with Java Code(though
    > everyone may know basic java) .
    I am not asking everyone to abandon graphical mapping. I am just wondering which one is better when you have skills for both.
    > 3. Lot of standard functions are available in GM
    > which you can choose, but you have to remember the
    > exact code for those in Java mapping.
    You can create functions in Java too. All you have to do is to remember the function name.
    Kenny

  • Couln't  save a buffered image as BMP with java 1.4

    Dear friends,
    I tried to save a buffered image as BMP with java 1.4. When I run the program ,it executes sucessfully, but no image wasn't created. When I tried the same code with java 1.5 got the right result.
    This is the code I have written.
    public static void saveBMPFile(BufferedImage bufferredImage, String fileName) throws Exception{
              // TODO Auto-generated method stub
              try {
                   Iterator iter =
                        ImageIO.getImageWritersByMIMEType("image/bmp");
              // Get first writer
                   if (iter.hasNext()) {
                        ImageWriter writer = (ImageWriter) iter.next();
                        ImageWriteParam iwp = writer.getDefaultWriteParam();
                        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                        iwp.setCompressionType("BI_RGB");                    
                        FileImageOutputStream fios = new FileImageOutputStream(new File(fileName));
                        writer.setOutput(fios);
                        IIOImage image = new IIOImage(bufferredImage, null, null);
                        writer.write(null, image, iwp);
                        bufferredImage.flush();
                        fios.flush();
                        fios.close();
         } catch (Exception e) {                 
         throw e;
    please help me to find its solution.
    thanks & regards
    K P Jyothish

    Please use code tags http://forum.java.sun.com/help.jspa?sec=formatting
    I can see no else for "if (iter.hasNext()) {", so if no encode is found, no error message would be displayed.

  • Problems with Runtime.exec() and certain Unix processes

    Certain Unix processes don't behave correctly when run from Java using Runtime.exec(). This can be seen by running /bin/sh and trying to interact with it interactively. The issue appears to be that /bin/sh (and many other Unix tools) are checking the file handles on the spawned process to see if they are associated with a TTY.
    Is there any way to associate a process spawned by Runtime.exec() with a terminal or alternatively, is there a JNI library available that would setup the process correctly and still provide access to the input and output streams?
    Our objective is to have the flexibility of expect in being able to run and interact with spawned processes. A bug was opened at one point but closed back in 1997 as being a fault in the spawned process, not Java.
    Bug ID: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4058689

    #include <stdio.h>
    void doit() {
    int c;
            while((c=getc(stdin)) != EOF) {
                    printf("%c",c);
    int main() {
            freopen("/dev/tty", "r", stdin);
            doit();
    }This program reopens its standard input against /dev/tty and catenates it to stdout. And voila, it takes its standard input from the terminal, even though it was started with stdin against /dev/null..
    $ gcc b.c -o b
    $./b < /dev/null
    buon giorno
    buon giorno

  • Opening a UNIX shell in Java

    Hi,
    I need to simulate the machine's native shell (e.g. cmd\sh in case of windows\unix respectively). For that I open up a UNIX shell in my Java program using the usual manner:
    Runtime.getRuntime().exec("sh");Then I use the input and output streams of the Process in order to "communicate" with the process.
    My code works fine with windows shell ('cmd') but with unix ('sh') I failed to retrieve the machine's prompt. I believe that the issue is unix-related and that the process I launched has no appropriate environment parameter.
    Any idea?
    Thanks in advance

    Thanks for your fast reply.
    Although the article was interesting and did review the java.lang.Runtime quite good, it didn't help me as I have a specific problem with Unix OS and the article deliberately (or not) ignored that.
    I noticed that when I print the environments variables in my java application I get a partial list which doesn't contain the prompt (for instance the SP1 variable) whilst execute the 'set' command (not from java) i get a longer list and the prompt variable appears there.
    Any idea how should I execute the shell through java in order to receive the prompt?

  • Is annotation processing the same for Java 5 and Java 6?

    I've been trying to use a package of annotations and processors that was evidently originally designed to be used with "apt" and Java 5. When I try to use this stuff with Java 6 I was assuming that, since the Java 6 javac handles annotations, I could just use javac instead of apt - but it doesn't work; the annotation processors don't appear to be getting executed. It looks like I have to use apt for the Java 6 build after all.
    The question is, did the annotation mechanism change significantly between 5 and 6 that would account for this? Is there a way to adapt an annotation package (i.e. annotation classes and processors) that works with 5 so that it will work with 6 using javac instead of apt (or alternatively, is there a way to tell javac to process the older annotations in the same way that apt would)?

    PeteFord wrote:
    I've been trying to use a package of annotations and processors that was evidently originally designed to be used with "apt" and Java 5. When I try to use this stuff with Java 6 I was assuming that, since the Java 6 javac handles annotations, I could just use javac instead of apt - but it doesn't work; the annotation processors don't appear to be getting executed. It looks like I have to use apt for the Java 6 build after all.
    The question is, did the annotation mechanism change significantly between 5 and 6 that would account for this? Is there a way to adapt an annotation package (i.e. annotation classes and processors) that works with 5 so that it will work with 6 using javac instead of apt (or alternatively, is there a way to tell javac to process the older annotations in the same way that apt would)?If you have apt annotation processors, you can use the apt command in JDK 6.
    However, the javac in JDK 6 support standardized JSR 269 annotation processing; see the javax.annotation.processing package. JSR 269 annotation processing is significantly redesigned and improved based on experiences with apt.
    It would be "a small matter of programming" to port an apt annotation processor to JSR 269.
    Using apt in JDK 6, you can also run both apt and javac processors from a single command line invocation.

  • How to use Entrust with java application on unix platform

    Hi all,
    i have question regarding the use of Entrust with java application on unix
    1)I want to use Entrust for encryption/decryption of the file in my core java application on unix platform.
    What should be requiremnet for the same and how it is implemented?.
    2) I want to Use Entrust for Authentication purpose in my java based web application on unix platform.
    What are requirements for Entrust Authentication and how it is implemented ?

    any one has solution?

  • On Unix Clinet with Java 1.4.1 plug-in, text boxes are not working

    On Unix Client with Java 1.4.1 plug-in version, text box is not responsive (I am not able to enter anything).
    But If load the same applet on the same client by upgrading the plug-in to 1.4.2, it works. Is this a known bug in Java plug-in 1.4.1?
    Thanks

    Might be related...
    http://developer.java.sun.com/developer/bugParade/bugs/4806274.html

  • Preventing multiple instances of same application - started with "java app"

    I need to ensure that only one instance of an application runs at any given time.
    As far as I know launching it twice with "java appName" will run each in its own memory space, so it is not immediately obvious how to achieve it. I considered using a database entry or environment variable, but those would need to be cleared on exit and therefore be at risk of not being cleared if the application crashes or hangs.
    Is there a Java API call that would allow me to do a check for other instances of the same application... safely?

    Create a ServerSocket on a fixed port number that isn't used by any other application. If you get a BindException, your application is alread running.

  • Ability to process several raw files with the same content but with different exposure into the single picture

    Can you add to the Lightroom an ability to process several raw files with the same content but with different exposure into the single picture?
    Base raw files can be given with exposure bracketing during shooting, for example.
    The goal - to get maximum details in darks and lights (if we use the "ligths recovery" or "fill lights" we lose the quality because raw file just have no all required information).
    The similar (but not the same, only the idea) thing - is High Dynamic Range Photography in Adobe Photoshop
    Thank you

    The plugin LR/Enfuse does this already. And of course Photomatix have a plugin available for Lightroom. This essentially amounts to pixel editing, which is beyond the range of Lightroom's metadata editing.

  • File processing failed with java.lang.StringIndexOutOfBoundsException:

    Hi
    I´m reading and sending files to an FTP server using SAP PI. I use file content conversion.
    Everything has been working fine for months - but now the server was changes to a new host. The only thing changed was the host/user and pass.
    But sending too the server fails with this error:
    File processing failed with java.lang.StringIndexOutOfBoundsException: String index out of range: -27
    Any body who has a clue??
    Reading files works ok. And i can transfer files to the FTP server with FileZilla without problems.

    In the file transfer by ftp:
    2011-10-03 17:27:08     Information     Transfer: "BIN" mode, size 737 bytes, encoding -.
    2011-10-03 17:27:08     Error     File processing failed with java.lang.StringIndexOutOfBoundsException: String index out of range: -27
    2011-10-03 17:27:08     Error     Adapter Framework caught exception: String index out of range: -27
    2011-10-03 17:27:08     Error     Delivering the message to the application using connection File_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error occurred while connecting to the FTP server "nnn.nn.nnn.nnn:21": java.lang.StringIndexOutOfBoundsException: String index out of range: -27.
    Its on the adapter level. All mappings etc are fine. And as i write has been for months. The only thing changed are the FTP server

Maybe you are looking for

  • Fill in the blank and advanced actions

    Hi everyone, I'm wondering whether this can be accomplished with fill in the blanks standard quiz question or whether I need use Advanced Actions. I have a graphic of a form that needs to be correctly filled out with specific values. There are multip

  • Document Copy PS/DMS module

    Hi All, I need to copy the document from one place/level to another place/level. I am not supposed to use down load and upload concept as ther could be more documents per one review. It's basically PS module. I just want to checkout doc form one plac

  • IOS doesn't accept dot1x commands on 4510r+e

    I am running a 4510 with a SUP-8. I am trying to implement 802.1x for NAC, but the switch refuses the interface-level command. Below is the entire config I am trying to implement and the results. Any ideas as to why it rejects the interface level com

  • Floor Plan Manager

    Hi, If someone has a step by step tutorial or anything material w.r.t development self service applications using sap's FPM then plz help me. Thx in advance frienldy regards ertas

  • I can't open the Lightroom 4 Mac upgrade.

    I downloaded the upgrade from Adobe and installed it on the computer.  Now when I try to open it I get the following error message: "You can't open the application Adobe Photoshop Lighroom 4 vecause it is not supported on this type of Mac." I have th