Directing output to shell prompt

I'm well aware of the platform independence of java, but is there any way to execute shell commands within java? Maybe there are specific packages that have utilities for doing something like this? Or are there ways to execute other programs (anything executable, ie shell scripts) from within java? Any help would be greatly appreciated.

try {
  String command = "ls";
  Process child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
  e.printStackTrace();
}PS! which was the question you wanted to ask? the one in subject line, or the one in message? or both?

Similar Messages

  • Difference of output from cron job & shell prompt

    We have a script in production like:
    sqlplus -s <username>/<password><<EOF
    set head off
    set feedback off
    set numwidth 4
    set serveroutput off
    spool /tmp/test1.txt
    prompt column1 , column2
    select column1||' , '|| column2 from <table> where <condition>;
    spool off;
    EOF
    echo "Best Regards," >> /tmp/test1.txt
    echo "IT Team" >> /tmp/test1.txt
    When run one time from the shell prompt, it gives the correct value like-
    column1, column2
    <column-1>, <column-2>
    Best Regards
    IT Team
    But when I run it from a cron job twice the output is like-
    column1, column2
    <column-1>, <column-2>
    Best Regards
    IT Team
    Best Regards
    IT Team
    The problem in the above output is that the bottom 2 statements,
    Best Regards
    IT Team
    keep getting repeated the number of times when the cron job is run. If the cron job is run 3 times the set of 2 statements get repeated thrice.
    I hope, I have been able to explain the problem.
    Requesting a reply to my query.
    Regards

    Locking this duplicate post - Difference of output from cron job & shell prompt

  • I want to configure shell prompt.

    Hi,
    I want to configure my shell prompt, but, I am unable to find either .cshrc or .profile file in my "/" directory.
    Is there any other possibility through which i can configure my shell prompt so that it displays hostname:current working directory before "#".
    Rahul

    Hi Rei,
    Thanks for the answer, we can make it more useful by adding following instead of limiting to one user "root"
    set prompt="`whoami`@`hostname` %/#"

  • Running odihragent from shell prompt

    Hi
    I am currently trying to run odihragent from a shell prompt to do some debugging however I am not sure of the date format that it expects? Can anybody help?
    /oracle/10gASR2/ldap/odi/bin/odihragent OracleHRAgent connect=find login=apps pass=*** date=200501011200
    status= -1
    Error - ORA-01722: invalid number
    Error in OCIStmtExecute
    Error in Execute
    HR Agent failed with Status:2

    well, the problem is not with the command line arguments. it doesnt matter if we get the input from the user through command prompt or GUI. The problem is only in the handling of the change in exitValue during running.

  • Javac in shell prompt jdk1.5_09 update

    hi could anyboddy tell me that in shell prompt in windows why javac doesnt work what's the alternative

    goto
    start> Control Panel> System
    In the advanced tab click the Environment Variables button.
    In the System Variables section highlight the variable called 'path'.
    Each path is seperated by ; just add the path to the directory containing javac.exe

  • Why can't I get AVCHD to look as good in FCP7 as direct output from camera

    I've been comparing my Sony HDR-SR12 footage and noticed a problem after import with FCP and other Mac apps.
    Quality issue:
    items in motion not as clear/smooth in FCP and subsequet exports as it is directly from to monitor OR files opened in Windows with media player. It is not very noticable until you project it on a 100 screen or play in full screen on an imac.
    it is most noticable with scenic landscape pans..even slowly.  Items moving across screen have a slightly strobed or choppy/blur effect that make it difficult to focus on them. Again.. NOT a problem directly from camcorder to projector/montior or playback on Windows media player, so it's not the camera file.
    exporting to quicktime doesn't help, so it is not likely a processor/disk speed issue on playback.
    Sony file spec:  AVCHD 1440X108060i 29.97fps
    Camera output- mini HDMI-(monitor), USB(file transfer).
    What I have tried.
    OS 10.6.8 with FCP7- import AVCHD files with pro res 422 codec. Timeline auto prompt switched to proper setting. Still no improvement- I then changed setting for lower/upper field, etc. No difference.
    iSkysoft AVCHD/MTS converter- playback in quick time- still no improvement.
    Booted in Windows- converted AVCHD files to WMV- inital trial not any better, plus other resolution/qaulity issues.
    I have an iMac 2.8Ghz intel core i7, 8gig ram and 7200speed internal HD.
    Anybody out there have similar problems?
    thanks!

    Final Cut Pro shows you a proxy image. To see the real deal you need a 3rd party card/external box feeding a broadcast monitor.
    If viewing using the Quicktime player, make sure you use the QT7 version. QTX is not ready for primetime.
    Also, open up the QT 7 preferences and make sure you have "Use high-quality video setting when available" checked.
    x

  • Set audio in/output with shell command

    Hi.
    I want to switch the systems audio input and output with a shell command. I've found a command that can set the volume. Maybe someone can tell me if this is possible and if so, which command i need.
    osascript -e "set Volume 0"

    I think there's a messy way of doing it in AppleScript by addressing the menus in the System Preferences. But if I were you I would have a look at the tool that someone has created here:
    http://code.google.com/p/switchaudio-osx/
    It addresses CoreAudio directly I think to change the input/output method:
    will@Newton:~/Downloads/SwitchAudioSource-v1> ./SwitchAudioSource
    Please specify audio device.
    Usage: ./SwitchAudioSource [-a] [-c] [-t type] -s device_name
    -a : shows all devices
    -c : shows current device
    -t type : device type (input/output/system). Defaults to output.
    -s device_name : sets the audio device to the given device by name
    will@Newton:~/Downloads/SwitchAudioSource-v1> ./SwitchAudioSource -a
    Built-in Microphone (input)
    Built-in Input (input)
    Built-in Output (output)
    will@Newton:~/Downloads/SwitchAudioSource-v1> ./SwitchAudioSource -c
    Built-in Output
    will@Newton:~/Downloads/SwitchAudioSource-v1> ./SwitchAudioSource -t input -s 'Built-in Input'
    input audio device set to "Built-in Input"

  • Web Reports - directing output to local printer.

    We are running Forms/Reports web enabled, and we are designing
    reports, that must send the output directly to the customers
    printers without first showing them in a browser.
    Can anyone please tell me how to do this?
    Regards
    Benny

    There is a utility from Oracle called Remote Report Printing
    Utility. This is meant for sending Web Reports ( HTML,PDF)to a
    local printer. Though I have this utility+doc I havent
    successfully done it.
    If u want I can send it u.
    Hope this Helps

  • How to pause output in command prompt

    I have 10 sentence for instance, i want to display one sentence each time i press enter. Does anyone know how to do it in java?(command prompt)

    1. Wrap the default System.err and System.out in your own PrintStreams
    2. Replace them with your wrapper classes (see System.setErr(PrintStream) etc)
    3. In the wrapper classes, parse output looking for '\n' chars + any time you find one, write to that point, then read a return from System.in

  • [SOLVED] Xmonad and shell prompts

    Hi
    Is it possible to make this prompt/shell support pasting commands? I can only interact with it using the keyboard. Thanks
    -- Prompts
    import XMonad.Prompt
    import XMonad.Prompt.Shell
    myXPConfig :: XPConfig
    myXPConfig = defaultXPConfig
    { font = myDroidFont
    , bgColor = myColorGrayBg
    , fgColor = myColorBlue
    , bgHLight = myColorBlue
    , fgHLight = myColorWhite
    , promptBorderWidth = 0
    , position = Bottom
    , height = 16
    , historySize = 100
    , historyFilter = deleteConsecutive
    Last edited by valvet (2010-11-09 22:08:30)

    brisbin33 wrote:
    How are you pasting? Have you tried S-insert or middle click?
    If it's true that the prompt does not support pasting of any sort, then your config will be irrelevant and the fix/change will almost certainly have to occur in the X.Prompt internals.
    Hi
    Yes, I tried both. Moving the cursor over the prompt window, it has no "edit" cursor, as in a terminal. Shift insert is the same result.
    Well, OK - but would be a nice feature :-). I'll play with it.
    Thanks

  • Interacting with a shell prompt

    I am using the following piece of code:
    String command = ".. some unix command ..";
    Process p = Runtime.getRuntime().exec(command);
    BufferedReader buffIN = new BufferedReader(new InputStreamReader(p.getInputStream()));
    int c;
    while ((c = buffIN.read()) != -1) {
       System.out.write(c);
    BufferedWriter buffOUT = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
    buffOUT.write(".. some interaction command ..");
    int c2;
    while ((c2 = buffIN.read()) != -1) {
       System.out.write(c2);
    buffIN.close();With this code, I can invoke ".. some unix command ..", read the output from the shell, but I am unable to send command ".. some interaction command .." to the shell and make it effective.

    You need to flush the data from the BufferdWriter, so the process will get it.
    So try as follows:
    buffOUT.write(".. some interaction command ..");
    buffOUT.flush()

  • Data Merge: Direct output to PDF

    I'm using CS3 Design Premium, Mac Pro, and I have a single page letter that uses variable images and text from a CSV file. I routinely have 4000+ records with about 10 different variables each. Normally, I break it up into about 250 chunks, export to a PDF, and then combine all of the PDF into one file.
    Is there a cheap (under $100 or FREE) plug-in, script, or something else that takes the original document and outputs the merged PDF?
    Thanks in advance!

    I just set up a simple test file with 8000 records of three fields each. 21 records per page.
    I didn't use a stopwatch but direct-export to PDF seemed slightly faster than the creation of the merged document.
    And since the export of the merged document failed I would say that the direct route to PDF is rather a good feature, don't you know.

  • GT70 2oc - 770m direct output

    Could upload a screenshot of this tab in the "GT70 2oc"
    Thanks

    Quote from: MrFox;109243
    It is an example image of what I need.
    I want to know which output is connected directly to the GPU.
    To play 3D content
    Sorry, it's routed via Intel (GT70 680M).

  • Capturing output of shell script in Automator

    I have an Automator work flow that includes the execution of a shell script.  The script in turn executes a Perl script and captures its output on a file.  This may sound a bit convoluted, but the Automator part was intended to automate disparate scripts that were already made, so I just "glued" them together.
    The shell script is like this:
    cd "/Users/username/Documents/Development/"
    ./script.pl "$1" 2>&1 >out.log
    The problem is that, after execution, "out.log" contains the output from STDOUT, but not STDERR.  I know because if I run "script.pl" from the Terminal, I get not only the normal output, but a couple of errors or warnings spit out by the script.
    I was under the impression that "2>&1>out.log" would redirect STDERR to the filehandle used by STDOUT, and then redirect STDOUT to the file, with the ultimate result of redirecting both filehandles to the output file.
    Is there something I'm missing?  How can I capture the STDERR from the script as well?  Keep in mind that the shell script is executed from an Automator work flow.
         Thanks!
         -dZ.

    ./script.pl "$1" >out.log 2>&amp;1
    It is important to redirect in the correct left-to-right order.
    First move STDOUT (file descriptor 1) to the file, THEN move STDERR (file descriptor 2) to where STDOUT is NOW pointing.
    You moved STDERR first, then moved STDOUT, leaving STDERR behind.

  • Exchange Management Shell prompt for connection credentials?

    Some time ago I came across an article where a couple of modifications to the shortcut to the EMS would allow a connection to a specific server and then prompt for credentials for that connection.
    Removing the -auto and replacing with -serverFQDN [servername] covers the 1st part, but I can't recall what allowed the prompt for credentials to the other machine.
    I'm looking do do this from a Win7 machine, where I must login with one account but another account has Exchange permissions.
    It's driving me nuts, because I had it working and lost the shortcut in a machine reload and can't recall what I had done.

    Slightly modified, but nothing important was removed.
    C:\Users\[loginid]>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ver sion 2.0 -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin \RemoteExchange.ps1'; Connect-ExchangeServer -ServerFQDN [servername] -Credential (Get-Credential)"
             Welcome to the Exchange Management Shell!
    <tip snipped>
    cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters:
    Credential
    VERBOSE: Connecting to [servername]
    [servername] Connecting to remote server failed with the following error message : Access is denied. For more informati on, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo         
    : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
       eption
        + FullyQualifiedErrorId : PSSessionOpenFailed Failed to connect to an Exchange server in the current site.
    Enter the server FQDN where you want to connect.:
    Doing a New-PSSessoin using the same credentials is successful.
    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
    http://[servername]/PowerShell/ -Authentication Kerberos -Credential $UserCredential import-pssession $Session
    cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters:
    Credential
    WARNING: Some imported command names include unapproved verbs which might make them less discoverable. 
    Use the Verbose  parameter for more detail or type Get-Verb to see the list of approved verbs.
    ModuleType Name                               
    ExportedCommands
    Script     tmp_e9ed0738-3c62-458b-bdc8-7451...
    PS C:\
    Using CAC login, or domain/username/password produces the same results.

Maybe you are looking for