Command line program execution problem.

Hey there, I'm about to complete my Java thesis project, but I can't fix a problem: i have to find a command line programme (which is in python but i think its not a big deal) through a java programme. Getting some information around I ended up i could execute the program with the command:
Process proc = Runtime.getRuntime().exec("...");
and create the streams:
OutputStream out = proc.getOutputS 14.49
InputStream in = proc.getInputStream();
the problem is that calling a programme which prints on screen something and then it ends (ex. ipconfig) the following sequence works out:
do
int i=in.read();
if(i==-1) break;
System.out.print((char)i);
}while(true);
instead in the specific case of the programme that i need to execute it canno't work because this programme after its opening prints a couple of lines, at this stage you need to type the input in and when the eof font is sent the output is printed. i've tried to send the input thru OutputStream but the execution gets stuck when it reads the output (in.read());
Can you guys help me out? What do i need to do? Please it's very important, let me know ASAP.
Thanks very much,
Fabio

I would not recommend the use of raw "InputStream" for much of anything.
Try Scanner if you can use JDK5, if not, try BufferedReader.
Scanner:
Process proc = Runtime.getRuntime().exec("...");
BufferedOutputStream out = new BufferedOutputStream(proc.getOutputStream());
Scanner in = new Scanner(proc.getInputStream());
while(in.hasNextLine()) {
     String s = in.nextLine();
     System.out.println(s);
}BufferedReader:
Process proc = Runtime.getRuntime().exec("...");
BufferedOutputStream out = new BufferedOutputStream(proc.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String l = " ";
while(l != null) {
     l = r.nextLine();
     System.out.println(s);
}

Similar Messages

  • Creating a command line program reading AEP/AEPX files?

    I'm new with After Effects SDK, and I wanted to know if it's possible to use SDK to implement a command line program that gets information such as duration and frame rate in AEP/AEPX files.
    aerender, a command line render program provided by After Effects, prints out these information before rendering. But it doesn't seem to be able to print out the information without doing rendering.
    I saw a related thread here: http://forums.adobe.com/thread/844341
    But what I want is simpler. I don't need to alter the AEP/AEPX files. I just want to obtain the information quickly from an AEP/AEPX file. Is it possible to write such a tool using SDK?
    Thanks!

    hi eliang.cs!
    yes, i'm the same guy who answered on the other thread.
    everything the API does, it does through AE as a plug-in.
    so if you have AE running (even just the renderer), your project loaded and your plug-in present, you can access all the data you described with no problem, and export it out in whatever way you want. (a plug-in is actually a DLL, so you can do anything you want, even on an OS level)
    you can access the data on all elements of the project including comps, layers, footage, render queue, ect...
    having said that, you can do all of this using a script instead of a plug-in.
    scripts are much easier to build.
    perhaps there's even a script out there that does what you're looking for, or something very close that could easily be adjusted.

  • Is there a command line program that converts WAV to SWF?

    Is there a command line program that converts WAV to SWF?
    thanks

    why you want to do that? you can import your wav into the
    swf!

  • Cope: a command-line program colouriser

    cope is a wrapper around various command-line programs that takes their output and adds colours - a sort of ornamental cope, if you will.
    It's written in Perl, and requires version >= 5.10, so installation may be a bit complicated if you have to track down the dependencies. It installs several scripts in a directory, each one calling the program it's named after, only highlighting its output using regexes. Then you add this directory to your $PATH, and everything should (hopefully!) be seamless.
    Currently it's in release candidate status - I've been using it personally for a few weeks and nothing catastrophic has happened so far, so there's little point me keeping it private.
    Screenshots:
    Main site: http://stuff.cytzol.org/cope/
    GitHub: http://github.com/cytzol/cope

    PKGBUILD
    # Contributor: denton <e9203.00 gmail com>
    pkgname=cope-git
    pkgver=20091208
    pkgrel=1
    pkgdesc='A colourful wrapper for terminal programs'
    arch=(any)
    url=http://stuff.cytzol.org/cope/
    license=('GPL' 'PerlArtistic')
    depends=("perl>=5.10")
    makedepends=(git)
    provides=(cope)
    conflicts=(cope)
    install=$pkgname.install
    _gitroot=git://github.com/cytzol/cope.git
    _gitname=cope
    build() {
    cd $srcdir
    # Git
    msg 'Connecting to Git server...'
    if [ -d $_gitname ] ; then
    cd $_gitname && git pull origin || return 1
    msg 'The local files are updated.'
    else
    git clone $_gitroot || return 1
    fi
    msg 'Git checkout done or server timeout.'
    msg 'Starting make...'
    rm -rf $srcdir/$_gitname-build
    git clone $srcdir/$_gitname $srcdir/$_gitname-build || return 1
    cd $srcdir/$_gitname-build
    # Build
    PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1
    make || return 1
    make install DESTDIR=$pkgdir || return 1
    # Remove perllocal.pod and .packlist
    find $pkgdir -name perllocal.pod -delete
    find $pkgdir -name .packlist -delete
    cope-git.install
    post_install() {
    echo 'Prepend /usr/share/perl5/vendor_perl/auto/share/dist/Cope/ to $PATH'
    post_upgrade() {
    post_install
    First time making a perl package. It puts files that shouldn't be in */site:
    /usr/bin/perlbin/site/envpath
    /usr/lib/perl5/site_perl/5.10.1/IO/Pty.pm
    /usr/lib/perl5/site_perl/5.10.1/IO/Tty.pm
    /usr/lib/perl5/site_perl/5.10.1/IO/Tty/
    /usr/lib/perl5/site_perl/5.10.1/IO/Tty/Constant.pm
    /usr/lib/perl5/site_perl/5.10.1/List/MoreUtils.pm
    /usr/lib/perl5/site_perl/5.10.1/Params/Util.pm
    /usr/lib/perl5/site_perl/5.10.1/auto/IO/Tty/Tty.bs
    /usr/lib/perl5/site_perl/5.10.1/auto/IO/Tty/Tty.so
    /usr/lib/perl5/site_perl/5.10.1/auto/List/MoreUtils/MoreUtils.bs
    /usr/lib/perl5/site_perl/5.10.1/auto/List/MoreUtils/MoreUtils.so
    /usr/lib/perl5/site_perl/5.10.1/auto/Params/Util/Util.bs
    /usr/lib/perl5/site_perl/5.10.1/auto/Params/Util/Util.so
    /usr/share/perl5/site_perl/5.10.1/Class/Inspector.pm
    /usr/share/perl5/site_perl/5.10.1/Class/Inspector/
    /usr/share/perl5/site_perl/5.10.1/Class/Inspector/Functions.pm
    /usr/share/perl5/site_perl/5.10.1/Env/Path.pm
    /usr/share/perl5/site_perl/5.10.1/IO/Stty.pm
    /usr/share/perl5/site_perl/5.10.1/IO/stty.pl
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/CC.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/SEN.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1035.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1738.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1808.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2384.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2396.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2806.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/fax.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/file.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/ftp.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/gopher.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/http.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/news.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/pop.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/prospero.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/tel.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/telnet.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/tv.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/wais.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/_support.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/balanced.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/comment.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/delimited.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/lingua.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/list.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/net.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/number.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/profanity.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/whitespace.pm
    /usr/share/perl5/site_perl/5.10.1/Regexp/Common/zip.pm
    And as shown by the previous list, I haven't fetched these binaries (are they in the repos?):
    Env::Path
    File::ShareDir
    IO::Handle
    IO::Pty
    IO::Stty
    List::MoreUtils
    Regexp::Common
    Term::ANSIColor
    Everything works, except cope_path.pl.
    Last edited by denton (2009-12-08 09:14:37)

  • Fast command-line program which displays connectivity

    Hi
    I'm looking for a command-line program which can show whether or not my network interface has an IP address or not. It could use "ifconfig" to extract the information, I don't really care, but it has to be *fast* and it cannot require root access.
    Thanks

    Thanks, but if someone knows some sed/awk magic to get only the interface's IP address, that would be great!
    EDIT:
    Using the little "sed" I know, this is what I came up with:
    ifconfig wlan0 | grep -w inet | sed "s/^\\s*//" | sed "s/^inet addr://" | sed "s/\\s.*//"
    EDIT2:
    Now I have this reasonable command:
    ifconfig wlan0 | grep -w inet | sed "s/.*inet addr:\([^ ]*\).*.*/\1/"
    Last edited by skorpan (2009-06-07 16:44:19)

  • Tagging command line programs in subtle?

    I'd like to be able to tag command line programs so I can assign them to specific views and gravities within those views.
    For example, I'd like to be able to have 'gclacli calm' be recognized by a tag so it appears in my 'agenda' view and assign it a gravity. Is there a way to do this? Right now the best I can do is limit xterm to different views but they still move around when I change  views.
    Last edited by tinySpark (2012-06-14 18:04:12)

    None of these options have worked.
    for the user variables, i just create a new one called "Path" and type in my path to java \bin right?
    This is quite frustrating. Thanks for the help though!
    --Brenton                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Uninstalling Command Line Programs

    I've searched these forums and the internet for an answer to this, but there doesn't seem to be anything out there, so I hope this will be helpful to others as well.
    I have some open source command line programs that I downloaded, compiled, and installed as part of some exercises I was doing in a book on open source GIS (geographic information systems). What I want to know is how do I remove those programs? I can find references for compiling and installing these types of programs all over the internet, but nothing about removing or uninstalling them.
    Also, any ideas for good, up-to-date references on learning Unix in Mac OS X would be appreciated too. I'd like to get more into open source GIS, but from the research I've been doing, knowing Unix would help a lot.

    What process did you use to compile and install? Was it a configure, make, make install sequence, which is fairly common? If so, go back to the directory where you did that, and try, for example, 'make uninstall'. This might work.
    Look for output files from the compile and install process (perhaps config.log) that might tell you where files will be installed. Perhaps in /usr/local?
    Is there a README or INSTALL file that came with the source code? Documentation about what was installed where might be there.
    If worst comes to worst, and you're really determined, you could repeat the compile and install steps, but with a before and after listing of all the files in your system, and compare the listings. Or use the find command immediately after the reinstall, looking for recently created or changed files (the 'mtime' option or similar).

  • Problem executing command line program

    Hi I have a tuxedo command line app in Solaris 2.6. I was able to execute the program from unix prompt however when I try to do it from JAVA program, it does not work.
    I have to execute from command line as follows
    $ud32<SPACE>-U<SPACE>login<nl>
    SRVCNM<TAB>CB_EXESUB<nl>
    CLFY_SUB<TAB>ExeternalMsg<nl>
    EQUIP_ID<TAB>1<nl>
    <nl>
    during command line execution from second line on you will not get the prompt. After entering a balnk line the program will execute and provide the output.
    I was aslo able to execute the program by putting the last 4 lines in a file(say test.bat) and executing by issuing following command at the unix prompt
    $ud32 -U sa<test.bat
    My java program as follows.
    import java.io.*;
    public class udexec {
    public static void main(String args[]) {
    try{
    Runtime rt = Runtime.getRuntime();
    System.out.println("Before");
    Process prcs = rt.exec("ud32 -U sa");
    System.out.println("After: " + prcs);
    InputStreamReader isr = new InputStreamReader(prcs.getInputStream());
    PrintWriter out = new PrintWriter(prcs.getOutputStream());
    out.println("SRVCNM CB_EXESUB");
    out.println("CLFY_SUB ExternalMsg");
    out.println("EQUIPID 1");
    out.println("");
    int ret = isr.read();
    String line;
    System.out.println("Before Print");
    System.out.println(ret);
    catch (Exception e) { System.out.println(e); }
    Any help will be greatly appreciated.
    Thank You
    Raju

    Hmm, maybe you should also give additional Excape Characters to the Process (so adding \t where you have written <TAB>, or adding \r to the lines).

  • Java command line programming in windows

    Here's what I want to do:
    -write .java files in a text editor
    -compile and run them from a command line, rather than using a
    compiler like codewarrior or MS J++
    Here's my problem:
    In a program that produces output, I can't seem to find a way to
    retain the output that goes off the screen in a DOS window. Is there
    a way to enable scrolling in a DOS window, or are there any
    alternative command line terminals for Windows? Any suggestions
    would be greatly appreciated.

    I think you can increase the Screen Buffer size which should give you a scroll bar. For this right click on the icon on the top left of the DOS window -select Properties - Go to Layout tab.
    Another option will be to redirect the output to a file
    java SomeClass > log.txt
    Hope this helps.

  • Setting column width in a command-line program

    Is there a way to send data to the screen in a command-line Java program that will be formatted as a number
    of columns with a set column width? I am looking for something similar to the C++ setw() I/O manipulator
    used in cout.
    Thanks,
    Steve

    If you go to: http://java.sun.com/docs/books/tutorial/essential/io/writingFiltered.html
    it will show you how to subclass a filtered output stream and add your own formatting methods.Then you can chain your new class to System.out
    like this:
    YourFilteredStream yfs = new YourFilteredStream(System.out); .
    Then:
    yfs.yourNewMethod(); goes directly to system out in the new format.

  • Command line program: can it implement keyListener??

    Hello,
    before I take the trouble to learn keyListener implementation, I am wondering if my program could even implement it. It is just a small game that just plays in the command window. I would like it to respond to the user pressing up, down, left and right keys. Is this possible with a keyListener or is this only possible in a 'windowed' application?
    And if you cannot register keys this way from the command line, then how would I make my program interactive. Do you know a link to an API description that explains how to set the program up to give a prompt?
    Thank you very much!
    -Mike.

    guess not...

  • How do I pause C command-line program?

    Hello. I'm writing a little command-line game app in C and I'm curious about how I can pause the program to wait for the user to hit return. I want the user to need to hit return (or having to hit any key would work too) to make the program continue, and I would like the key that was hit not to appear on the screen -- just a simple sort of "hit any key to continue" type thing. In C++ I think we used something like system("Pause") or something like that -- don't really remember, but any help here will be greatly appreciated. Thanks!

    Something like this will print a prompt, then wait for a keystroke:
    printf("Hit any key to continue> ");
    getchar();
    However in a console application, it's not so easy to prevent the user's keystrokes from being echoed. There are ways to turn the echo off for the keystroke then restore it, but those can depend on the environment. I'd need to know whether you're running your program in an Xcode console window, a Terminal window, or elsewhere. In short, don't go there unless it's quite important to you. The above prompt will show any chars that are keyed-in as text after the arrow, which is what a user would expect.
    Hope that helps!
    - Ray

  • Command line program install

    I need to install a program on several Macs that I manage. All Macs, save 1, are OSX 10.9
    I do not want to go visit each mac personally not to mention interrupt the user to install a quick support program. Does anyone know if it's possible to ssh and do a command line install for GoToAssist Unattended Client? This may be a G2A question rather than an OSX question, but I was wondering if anyone had any experience or advise for command line installing a program via SSH? This will allow me to do all the installs behind the scenes from my mac and not bother the users.
    Thank you all in advance!

    I was able to figure it out on my own and thought I would share in case anyone else needed the help later.
    $ sftp localuserAccount@IPaddress_or_DNSNAME
    password:(this will be your local user password)
    sftp> put /Users/myusername/Desktop/NewSoftware.pkg
    sftp>exit
    $ssh localuserAccount@IPaddress_or_DNSNAME
    password:
    $ sudo installer –store –pkg /Users/localuserAccount/NewSoftware.pkg
    password:
    Once the installation completes
    $exit
    In my case the remote computer that I installed the new software on needed to be rebooted but I will not always necessary.
    Cheers!

  • Open file in folder with command line program

    I have a file, which is in native format for a given program [1] I have installed. This program I can start from Terminal.app and within the program I can open the file. The question is if I can have associated with this specific filetype this program and when I double click on a file of this type I can have a Terminal.app opened with my program running inside opening the file for me.
    Btw, on a regular Linux/Unix I would just associate this filetype with the path to my program. On Mac I can associate only with .app.. Is there other way?
    [1] http://root.cern.ch/drupal/

    I do not fully understand your question.
    You need to make your program into an application. I have not programmed on Mac OS so I to not know the details. You could hack some existing app. I do know that the plist file for an app points to the starting program.
    Another work around would be to write an apple script file to call your program.
    This applescript invokes a unix program.
       Run in the Script Editor.
       Click on the Event Log tab to see the output from the log statement
       Click on Run
       For running shell commands see:
       http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
       -- Write a message into the event log.
       log "  --- Starting on " & ((current date) as string) & " --- "
       -- ask the user for the folder name.
       -- quoted form of (POSIX path of (choose folder))
       set theFolder to "/Applications/Utilities/Disk Utility.app"
       set theFolder to quoted form of theFolder
       log "quoted form is " & theFolder
       -- running two Unix commands. Separate with a semicolon 
       set fromUnix to do shell script "cd " & theFolder & "; ls -ld ."
       log fromUnix
       display dialog fromUnix giving up after 30
    end run
    This applescript program received a file dropped on it.
    There is a lot of extra stuff but look at on open dropped_items This line gets a list of files dropped on the applescript. Your have to change the name format.
    on open dropped_items
       -- Remember you need to turn on enable assistive devices
       -- this lets applications software to access screen elements
       -- blue apple > system perferences > universal access > enable assistive devices
       -- Write a message into the event log.
       log "  --- Starting on " & ((current date) as string) & " --- "
       -- set see to alias "Macintosh-HD:Users:mac:Desktop:app.html"
       -- set dropped_items to {see}
       set the_app to "Safari"
       repeat with dropped_item_ref in dropped_items
          --set UrlBase to "xzzx FILE://" & POSIX path of dropped_item_ref
          --display dialog UrlBase
          -- Activate
          activate application the_app
          -- Open the URL 
          tell application the_app
             open dropped_item_ref
             -- print dropped_item_ref
             tell application "System Events"
                tell process the_app
                   delay 3
                   -- click menu item "Print..." of menu "File" of menu bar 1
                   keystroke "p" using command down
                   delay 1
                   keystroke return
                   delay 10
                   keystroke "w" using command down
                end tell
             end tell
             --quit
          end tell
       end repeat
    end open

  • Program Execution Problem

    Dear All,
    I am in one strange problem. I have created one BDC program to upload. It gets uploaded and executed when I go through debugging ( I do not make any change while in debugging only do F5 and F6 and F8). But,  when I run it directly It does not upload data to one particular screen but gets executed with display with no errors.
    Can any one please suggest what could be the reason for this? I am really in a fix. Any inputs or suggestions is appreciated.
    Regards
    SM.

    While executing in No display/Error mode, the internal commit work or some action might not
    have worked properly. So use the following command where the process strucks.
    WAIT UP TO 5 SECONDS.
    (or)
    Check the BDC okcode properly while in ALL DISPLAY mode
    Regards,
    Prem

Maybe you are looking for