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!

Similar Messages

  • How to redirect output of an OS command to a stream???

    how can i redirect the output of an OS command (such as 'ls' in linux or 'dir' in windows) to a io stream???
    ....for example, assume i'm having a textbox and a button...when i click the button , i need the output of 'ls' to be in the textbox....i think execution of the command could be accomplished by Runtime's exec() ...but how to redirect outputs???

    You should find what you are looking for here:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Redirect output to file?

    Hi there,
    is it possible to redirect the output of a canvas3d to file (jpg or so)?
    greetz, ToM

    Use this as a starting point: http://forums.java.net/jive/thread.jspa?forumID=70&threadID=13134&messageID=101107#101107
    Mike

  • Redirect output

    i am coding an application which uses some open source libraries. i don't want to have anything output to the standard output. i have the control in my application, but when there is an exception or whatever other error condition, the open source libraries will output printStackTrace() to terminal window. just wondering how do i stop other libraries from printing out to screen without changing their code?
    thanks in advance

    you could also redirect the output to files when starting your application
    java yourprogram >> prog_stdout.txt 2>> prog_stderr.txt
    hf,
    dani

  • Redirecting output to J2EE server command prompt

    I am finding difficulty with reading the system.out.println() given in the server side code. J2SDK redirects it to System.out file, but most of the time, I am not
    getting the results. I tried to restart the server to get the value from buffer.
    But thats not working either. Is there any way for getting the output in the server prompt itself. Can I do any configuration changes for this.

    Start the J2EE server from the command prompt with "-verbose" option.
    Regards,
    Ashoke Bhowmick

  • Redirecting output when starting the server as Service

    Hi,
    I was wondering if there is any way to redirect the error to a log file if the
    weblogic server has been started as Service. We are getting some crashes and we
    are not sure what exactly the issue is. We have tried running it on the command
    line and we have been able to capture some info but if there is a way to do the
    same when starting it as service,it would be great
    thanks
    Sushil

    wls8.1 sp3:
    To redirect the output to log files you must redirsct standard out and standard error to a file.
    This can be done by following steps:
    1.     Create a backup copy of the WL_HOME\server\bin\installSvc.cmd master script.
    2.     In a text editor, open the WL_HOME\server\bin\installSvc.cmd master script.
    3.     In installSvc.cmd, the last command in the script invokes the beasvc utility. At the end of the beasvc command, append the following command option:
    -log:"pathname "
    where pathname is a fully qualified path and filename of the file that you want to store the server's standard out and standard error messages.
    The modified beasvc command will resemble the following command:
    "%WL_HOME%\server\bin\beasvc" -install
    -svcname:"%DOMAIN_NAME%_%SERVER_NAME%"
    -javahome:"%JAVA_HOME%" -execdir:"%USERDOMAIN_HOME%"
    -extrapath:"%WL_HOME%\server\bin" -password:"%WLS_PW%"
    -cmdline:%CMDLINE%
    -log:"d:\bea\user_projects\domains\myWLSdomain\myWLSserver-stdout.txt"
    4.     By default, every 24 hours the Windows service archives messages to a file named pathname-yyyy_mm_dd-hh_mm_ss. New messages collect in the file that you specified in the previous step.
    For information on changing the default behavior, see Changing the Default Rotation Criteria <http://e-docs.bea.com/wls/docs81/adminguide/winservice.html>.
    After you install the service and restart the Windows host, to view the messages that the server writes to standard out or standard error, do one of the following:
    §     Make a copy of the file that you specified and view the copy. The Windows file system cannot write to files that are currently opened.
    §     To view the messages as they are being printed to the file, open a command prompt and, using a DOS utility that supports the tail command, enter tail -f stdout-filename.

  • Redirecting output from launchd?

    I'm in the process of converting my existing cron tasks over to launchd and encountering a small-ish annoyance. I've gotten into the habit of writing cron commands like this, appending the output to a log file:
    some_command andaparameter >> /the/full/path/to/the/logfile.txt
    This just gives me a quick-and-dirty way to log activity from cron commands. When I do that in launchd, it doesn't go the expected location, but rather gets written out to the system log. Does launchd not support >> redirection like that or do I need to do it in some other way?

    An excellent gui shell is lingon http://tuppis.com/lingon/
    Apple Tutorial: Getting Started with launchd http://developer.apple.com/macosx/launchd.html
    launchd in Depth: http://www.afp548.com/article.php?story=20050620071558293
    launchd: One Programm to Rule Them All – Video presentation of launchd: http://video.google.com/videoplay?docid=1781045834610400422
    I've looked around on the web for a good run-down of what it can do and some examples, but found very little. Seems like a great tool. I'm surprised there aren't more examples and tutorials out there showing what it can do.

  • Don't redirect output or Runtime.exec()

    Hello, I am using Runtime.exec() to execute a .bat file on a windows xp machine. I am able to read the output within the java app just fine. The problem is that I don't want the output to be redirected to a java stream as the default behavior of Runtime.exec() enforces. Is there anyway to run a .bat file and have the output stay in the DOS window that appears?

    Thanks for the input so far. Here is more detail. I have to execute the bat file. No way around that one. I tried getting no window to pop up but the only solution I found to this was to create a shortcut and launch the process with a minimized window. Not to keen on this solution as it isn't very elegant. Plus it would be very very bad if the window was closed in the middle of execution. If anybody knows of a better way not to have the window show up I would like to hear it.
    So now I am stuck with a blank DOS window. I figure the next best thing is to just use the window and have the output that normally shows up there to actually show up there when launched from a java process. This way hopefully the user realizes something is running in the window and they shouldn't close it.
    You would think java would have some way to a launch a process and forget about it.

  • Redirecting output from 'cmd.exe /c'

    I am using Powershell 2009 on a WIN-Server 2008 R2
    I have seen several suggestions on how to "redirect" the output generated by a 'cmd.exe /c', but none of the suggested solutions were successful.
    I have a simple cmd
    cmd.exe /c my_program.cmd $file.basename
    This process creates a lot of screen output and this command is in a loop of all files in a directory.
    I want to capture the output to a file "$lgfile"
    I have used
    {content}
    >> $lgfile
    {content}
    Out-file -filepath $lgfile [no output]
    {content}
    `$lgfile 2`>>`&1 [error '&" is reserved for future use]
    I would be grateful for any suggestions
    Also, the reason I am using "cmd.exe /c" is because that is the only method i have been able to use successfully (my_program.cmd is calling an ORACLE compiler! and all other methods to execute this compiler did not work except as a cmd-file)

    I usually just pipe to Set-Content:
    cmd.exe /c my_program.cmd $file.basename | Set-Content $lgfile
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Redirecting output from plink

    I am currently trying to write a function that runs plink and captures the output from that process.  When I try StandardOutput I get nothing and when I try StandardError I get "Unable to read from standard input: The handle is invalid."  I can only assume that this means I am trying to read while plink is waiting for input.  I am also passing my command via a text file called apCommands.txt.  When I run this command manually it works and gives me the required output, I just can't figure out why I can't redirect that output so I can store it in a results file.  Here is the code I have right now.
    string pArgs = "-m \"" + ABSPATH + "\\apCommands.txt\" -ssh myHost -l user -pw password";
    string output;
    if (File.Exists(ABSPATH + "\\apTest.txt"))
    File.Delete(ABSPATH + "\\apTest.txt");
    StreamWriter apTest = new StreamWriter(ABSPATH + "\\apTest.txt");
    Process runAP = new Process();
    ProcessStartInfo apInfoStart = new ProcessStartInfo(ABSPATH + "\\plink.exe");
    apInfoStart.Arguments = pArgs;
    apInfoStart.RedirectStandardOutput = true;
    apInfoStart.CreateNoWindow = true;
    apInfoStart.UseShellExecute = false;
    runAP.StartInfo = apInfoStart;
    runAP.Start();
    output = runAP.StandardOutput.ReadToEnd();
    runAP.WaitForExit();
    apTest.WriteLine("Standard Output");
    apTest.WriteLine(output);
    apTest.Close();
    runAP.Close();
    Thanks,
    Joe

    I see.  I wasn't aware that it wasn't a reliable way to connect to ssh.  As for the error message that was from standardError.  I think the process may have been waiting for input when I was trying to read from StandardOutput and thats why I got that error message.  Also instead of redirecting StandardOutput I tried redirecting the output directly into a file by running a cmd process and passing the commands I wanted to run through StandardInput.  The underlined section is all I changed besides running this inside of a cmd process.  This did work for me but I would rather know how to do it using StandardOutput. 
    string dArgs = "cd \"" + ABSPATH + "\"";
    string pArgs = "plink -ssh myHost -m \"" + ABSPATH + "\\apCommands\" -l user -pw password > test.out";
    Process runAP = new Process();
    ProcessStartInfo apInfoStart = new ProcessStartInfo("cmd");
    //apInfoStart.Arguments = pArgs;
    apInfoStart.RedirectStandardInput = true;
    apInfoStart.RedirectStandardOutput = true;
    apInfoStart.CreateNoWindow = true;
    apInfoStart.UseShellExecute = false;
    runAP.StartInfo = apInfoStart;
    runAP.Start();
    runAP.StandardInput.WriteLine(dArgs);
    runAP.StandardInput.WriteLine(pArgs);
    I haven't tried reading the StandardOutput from this piece of code, but I will probably try it.
    Thanks,
    Joe

  • ALSA / pulse redirects output to input on microphone mute

    Hi guys,
    I got a problem with my sound setup.
    For some reason, when I mute my microphone hardware-sided (my headset has an automute when I raise the microphone) my output gets redirected to my input, i.e. people on Teamspeak etc. can hear what i hear.
    For some reason I am also missing the front microphone column in alsamixer, i only get a front microphone boost.
    If I disable "capture" in alsamixer in the playback area, it also disables it in the capture area - I am not sure what to do
    Please let me know what kind of info you need to troubleshoot
    Thanks

    Hi guys,
    I got a problem with my sound setup.
    For some reason, when I mute my microphone hardware-sided (my headset has an automute when I raise the microphone) my output gets redirected to my input, i.e. people on Teamspeak etc. can hear what i hear.
    For some reason I am also missing the front microphone column in alsamixer, i only get a front microphone boost.
    If I disable "capture" in alsamixer in the playback area, it also disables it in the capture area - I am not sure what to do
    Please let me know what kind of info you need to troubleshoot
    Thanks

  • Redirecting output with sudo

    Here is one that has been bugging me off and on for some time.
    I want to execute a program using sudo, and redirect its output some place to which user invoking sudo does not not have write permission
    Simplistically, something like:
    JoeUser$ sudo echo "Appended stuff" >> /etc/afile
    I understand why this won't work, but for the life of me,  I cannot find an incantation that works.  I think it is complicated by the use of commands that are intrinsic to the shall (cat, echo)
    I have been through the zsh and bash manuals and have tried various commands to define a block of code to no avail.
    Any hints?

    tavianator wrote:
    Hate to tell a forum mod to RTFM, but:
    man sudo wrote:sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
    If the shoe fits....
    Thanks everyone.  The pipe works in a lot of cases.
    Invoking bash with sudo and passing commands is the obvious way (once someone points it out).  I guess I could not break out of the box I had built in order to look at the problem from a different angle.

  • Redirecting output in Netbeans?

    After a few years of several languages, I am finding Java to be my home :) I really enjoyed the improvements that Sun has made with NetBeans 6. However, it doesn't output text to the console/command-prompt like it would in JCreator Pro. Even in JCreator Pro, I had to redirect the output and it was much easier given a few settings. For Netbeans, the output goes to an "Output Window." I find writing my ascii game is easier with the command prompt and so JCreator seems ideal if I can't get my preferred IDE set properly for the command prompt. Is there a way to get NetBeans to redirect its output from the Output Window to the command prompt? Thanks.

    I was able to get the "run" button to execute output to the console (command prompt). Doing so was not too difficult. I agreed with Leonardo that posting it here would be helpful for someone else. He was very helpful with our first few attempts on a similar task.
    In your workspace, click on the Files tab. Find build-impl.xml, double-click on the "run" property in the navigator window. It should bring you to something similar below. What I added was the "exec" open and end tags. Just paste this in there and you will be up and going.
    <target name="run" depends="init,compile" description="Run a main class.">
    <j2seproject1:java>
    <customize>
    <arg line="${ application.args}"/>
    </customize>
    </j2seproject1:java>
    <exec executable="cmd">
    <arg value="/k" />
    <arg value="start cmd /k java -classpath "${basedir}\${ build.classes.dir}" ${main.class}" />
    </exec>
    </target>

  • Cannot redirect output of FNDLOAD

    Hi All,
    We are using AIX 6.1 ML7 to host Oracle Apps. We are using FNDLOAD to migrate setups.
    We have big script running a number of FNDLOAD commands to load setups in a target instance. Problem is, we are not able to capture the output of these commands in a file. The echo commands in the script can be redirected using >>. but the log file names and errors printed by FNDLOAD are not getting redirected.
    What could be the issue?

    We are using AIX 6.1 ML7 to host Oracle Apps. We are using FNDLOAD to migrate setups.
    We have big script running a number of FNDLOAD commands to load setups in a target instance. Problem is, we are not able to capture the output of these commands in a file. The echo commands in the script can be redirected using >>. but the log file names and errors printed by FNDLOAD are not getting redirected.
    What could be the issue?What do you mean by the output of FNDLOAD? When running FNDLOAD command it only generates a log file and no output file is generated.
    Thanks,
    Hussein

  • Redirecting output after a "cat" command

    I first encountered this with "do shell script" in AS, and the issue also occurs in Terminal.
    Basically, I want to get contents from a file, make some changes via "sed ," and return the changed version to the same file -- but the file always winds up empty. Without the redirect, the commands work as expected.
    For example, in Terminal:
    cat --path to some file-- | sed 's/this/that/g'
    results in the expected changes (returned to Terminal)
    but
    cat --path to some file-- | sed 's/this/that/g' > path to some (same) file
    results in a blank file
    (The "sed" command isn't even necessary for this to happen; just trying to return the output of the "cat" command to the file results in a blank file.)
    I've certainly been able to accomplish this sort of thing with commands other than "cat." Is this something that's not possible with "cat" or do I have the syntax wrong?
    (Of course, I can get around this by following up with an "echo" command but, in "do shell script," that requires more code.)
    Thanks in advance for your comments.

    HI osimp,
       I've always thought that the "sed 's/this/that/g' < input > output" syntax looked cool because you can sort of see the flow of information. However, the end of the command is simply a pair of redirect directives. The first tells the shell to open the file and pipe the contents into the standard input stream of sed. Then the output of sed is piped into the output file.
       The command I was proposing, "sed 's/this/that/g' input > output", is simpler in that it tells sed to read the file directly rather than asking the shell to read it.
       You said above that you were interested in storing the result in a variable. That could be done simply with a command like:
    OUTPUT=$( sed 's/this/that/g' input )
    For many types of content this would work nicely but the shell will try to expand the output so plenty of things can cause errors. I was going to wait to post the above until I discovered a way around that expansion but I haven't had enough time to do that so I'm posting it and I'll see if I can improve it later.
       I know some about AppleScript and have written several scripts that combine capabilities of the shell with those of AppleScript. There are probably more people here that know AppleScript here than there are shell scripters on the AppleScript Discussion. You should try posting the whole question over here as well as over there. However, try and see if you can get the help of Deivy over there. He knows a lot about interactions between AppleScript and the shell.
    Gary
    ~~~~
       A memorandum is written not to inform the reader,
       but to protect the writer.
             -- Dean Acheson

Maybe you are looking for

  • Looking for a notetaking app that syncs with PC

    I use playbook for mobility but PC for work.  I am looking for a (simple) note taking app that will allow me to sync with PC - preferably via dropbox. I used to use cintanotes on PC but that doesn't sync to PB.  Looked at Evernote but seems bloated a

  • Should Third party order items appear in mD04

    Dear experts, We create third party orders where material is directly shipped to our customer from our vendors, material does not come to our inventory, why such orders appear in MD04 , not only orders the PO created for such delivery also appears, w

  • Apple's mail *****

    When signing into my Gmail account at Google's main website, it works completely fine. But today I was experiencing some trouble with mail on my MacBook Pro. So naturally I went to settings to try to solve the problem by signing out and back in. But

  • Separate legal regulation for customers and vendors / sanctioned party list

    Hi, since we want to separate responsibilities and mails for checking sanctioned party lists concerning customers (sales department) and vendors (purchasing department) we would like to split business partners using different legal regulations within

  • Wrongly debited expenses instead of asset

    Hi experts, Please suggest, here the user has wrongly debit expense instead of asset. It has been done though PO. Here, now i wan to be create an asset and how it will be done in sap.  Regards, Sudha