Accessing Unix-commands via JNI

Hello everyone,
I'm currently developing for an Solaris - SPARC - environment a java application, which is processing a huge amount of files without out GUI.
As there are some limitations the Java-File - Object gives me in respect of the desired platform-independency of java, I'm right now looking for a way of using Unix - commands like "ln" or "ls" via JNI. I have no problem with accessing this commands vie the Runtime.exec(command) - construct. But the overhead which it leads to, because every time a new Unix-Process ist forked to execute the command, is not acceptable for me.
I see a slight chance of using JNI, but I can't figure out, how to acces the Unix-Calls, I'd like to execute. Could anyone give me a hint.
Thank You a lot.
Thomas

I have no problem with accessing this
commands vie the Runtime.exec(command) - construct.
But the overhead which it leads to, because every time
a new Unix-Process ist forked to execute the command,
is not acceptable for me.Just create a background shell process that you feed commands when you need to.
This example should get you started.import java.io.*;
class PipeSh {
    private Process sh;
    private OutputStream shIn;
    private BufferedReader shOut;
    private BufferedReader shErr;
    PipeSh() {
        try {
            sh = Runtime.getRuntime().exec("sh");
            shIn = sh.getOutputStream();
            shOut = new BufferedReader(new InputStreamReader(sh.getInputStream()));
            shErr = new BufferedReader(new InputStreamReader(sh.getErrorStream()));
        } catch (IOException ex) { ex.printStackTrace(); }
    void execute(String cmd) {
        try {
            shIn.write(cmd.getBytes());
            shIn.flush();
            while (shOut.ready()) System.out.println(shOut.readLine());
            while (shErr.ready()) System.out.println(shErr.readLine());
        } catch (IOException ex) { ex.printStackTrace(); }
    private static String[] cmd = { "mkdir foo\n", "cd foo\n", "touch bar\n" };
    public static void main(String[] arg) {
        PipeSh ps = new PipeSh();
        for (int i=0;i<cmd.length;++i) ps.execute(cmd);

Similar Messages

  • Unix security and privacy setting unix command via apple remote desktop

    Could someone guide me on the unix command to set System Preferemces Security & Privacy to xx minutes [see screenshot please] via Apple Remote Desktop.
    https://dl.dropbox.com/u/5485939/osx_screenshots/sys%20pref%20security%20privacy .png
    Thank you,

    Pereference tend to be stored for the computer as a whole
    /Library/Preferences/
    or specifcally for the user
    /Users/USERNAME/Library/Preferences/
    well when I set required password for XX minutes... I see that
    /Users/USERNAME/Library/Preferences/com.apple.screensaver.plist modfication date & time changes to the current time & date... hMMM maybe the setting we want is stored here? Can we test this?
    If I check require password and then do the terminal command:
    defaults read ~/Library/Preferences/com.apple.screensaver
    I see
        askForPassword = 1;
        askForPasswordDelay = 0;
        tokenRemovalAction = 0;
    turn it off
    run the terminal command;
    defaults read ~/Library/Preferences/com.apple.screensaver
    I see:
        askForPassword = 0;
        askForPasswordDelay = 0;
        tokenRemovalAction = 0;
    so I can turn it on with
    defaults write ~/Library/Preferences/com.apple.screensaver askForPassword -bool TRUE
    and I can turn it off with
    defaults write ~/Library/Preferences/com.apple.screensaver askForPassword -bool FALSE
    So if a user is logged into a computer. I could send unix command as current console user.
    defaults write ~/Library/Preferences/com.apple.screensaver askForPassword -bool TRUE
    BUT what if the user is logged out? or there are more then one user on the computer?
    then I could run unix command as user root and send
    defaults write /Users/USERNAME/Library/Preferences/com.apple.screensaver askForPassword -bool TRUE
    (replace USERNAME with the user's short name.)
    but what if I don't know the user name? or names
    send unix command as root
    ls -al /Users/
    get back a list of folders
    bob
    surely
    shares
    and then do
    send unix command as root
    defaults write /Users/bob/Library/Preferences/com.apple.screensaver askForPassword -bool TRUE
    defaults write /Users/surely/Library/Preferences/com.apple.screensaver askForPassword -bool TRUE
    you could also do some thing like
    defaults write ~/Library/Preferences/com.apple.screensaver askForPasswordDelay -integer 5
    if you want to change the period of time to lock to 5 seconds
    or
    defaults write ~/Library/Preferences/com.apple.screensaver askForPasswordDelay -integer 900
    (900 seconds  / 60 seconds = 15 minutes)

  • Cant send UNIX commands via ARD

    I have ARD, and the option to send UNIX commands is greyed out. Help?

    On the client, apple menu, system preferences, sharing, Remote Management.
    If allow access is set to all users, then click the options button.
    else, select the user your using to connect to the client, and then click the option button.
    Make sure every thing is checked.
    click ok
    try again on ARD.
    Other things to try:
    quit and re-open ARD.
    delete, then  and re-add the client computer from ARD.
    unchecking, and then re- checking remote management on the client. (to force the service to restart)

  • Inconsistent results from hostname Unix command via ARD

    I sometimes get the DNS name and sometimes get the local sharing name.
    Some one pointed out to me
    % scutil --set HostName DNS-name
    as root will do the job.
    So the next question is can one get the Mac to cough up its DNS name or
    IP address without major acrobatics.
    For example
    % ifconfig en0 inet
    gives the IP address but you have to parse it out and
    % host IP-address
    will give the DNS name but again you have to parse it out.

    We have a bunch of machines that are all named via the Sharing panel in System Preferences. Our network is giving them a different DNS name. We'd like to be able to access the Sharing name via the command-line (hostname gives DNS name). I assume this is possible because Remote Desktop seems to get it somehow.

  • UNIX command via Java?

    Hello all,
    one of the useful commands in unix is sed
    I would like to use the functionality of sed in Java.
    Is there any free java api where I can send a command like
    sed -n pos1,pos2p filenamethanks
    Aykut

    @tschodt
    Well, you failed to mention that...I spend at least 5hours about writing an efficient Java code for big text file.
    Within this time I read 50 to 100 forum threads from other people who had the same problem.
    All these pages I had found via google. Do you want me to write everything, all actions I did? :-) I don't think so.
    Is everyone else happy to use Runtime.exec() to invoke "sed"? How should I know that? :-) I am not a java expert.
    The idea of forums generally is, to share knowledge with other people.
    Well, after you said that, I will use Runtime.exec() and invoke sed and read the results.
    If you think you really need a full Java implementation of sed and
    you have not been able to locate one, you could always write one yourself...I don't need a full Java implementation of sed, not really.
    But just because I didn't find it, does not mean for me, that this code is no where exists.
    First I try to write the code by myself, second, I try to find it on internet by searching in google.
    If I still have no solution, I write my problem here at sun-java-forum (sometimes also somewhere else :-) )
    It seems to me you are angry, no need to be ...

  • Software Update via Unix command but get updates from my OS X server?

    I have a OS X server which I use to manage how software update runs on the clients. Currently when you run software update from the client it connects to the server and downloads what it needs which is much faster than downloading it via the internet each time.
    now, I would like to run a unix command via ARD that would run software update against the local server. Does anyone know the correct syntax for this? Running softwareupdate -l -a does not work. Thanks

    I'm also in the process of getting my Xserve setup as an internal software update server. I haven't gotten to the point of testing this yet, but I was under the impression that once the clients were managed, any software update command would force the clients to retrieve their updates from your internal server as specified in the MCX settings.
    I have a OS X server which I use to manage how software update runs on the clients. Currently when you run software update from the client it connects to the server and downloads what it needs which is much faster than downloading it via the internet each time.
    When you say that currently when you run software update from he client it connects to the server and downloads updates, are you referring to running the graphical Software Update tool?

  • How to authenticate UNIX command?

    As specified in KB article TS2754 <http://support.apple.com/kb/TS2754> I'd like to use this UNIX command to correct a user's computer:
    dseditgroup -o edit -p -a admin -t group _lpadmin
    I am trying to send this UNIX command via Remote Access 3.3 but each time it says:
    Please enter user password:
    Authentication failed.
    I thought that the fact that I am connected to the computer via Remote Desktop using the admin user and specifying that same admin user in the "Send UNIX Command" command setup would work but it obviously doesn't.
    So how do I properly send this command via Remote Desktop?

    Ack - there's more:
    KB article HT3511 <http://support.apple.com/kb/HT3511> is also relevant since these are networked users with mobile accounts. The problem is the same though: the script causes a prompt for authentication and I don't know how to address that in Remote Desktop.
    This article adds an additional potential issue if I have to send out a UNIX command for each mobile user specifically. It's much nicer when you can send one command to the whole network.

  • Unix Command doesn't work in Tiger

    Hi,
    I've got labs of eMacs that I'm finally upgrading to Tiger. My image seems to work fine, but I'm running into a weird quirk with my "Send Unix" commands via ARD. We're doing NWEA testing and LOVE the unix commands because we can login to machines, turn on TestTaker, login to TestTaker, and select the correct test (math or reading) and the right version of the test.
    The script below works fine on a panther eMac.
    osascript
    tell application "System Events"
    keystroke "1" using command down
    delay 3.0
    keystroke ASCII character 31
    delay 2.0
    keystroke return
    keystroke "n" using command down
    end tell
    On my Tiger machines, the command stops on the:
    "Keystroke ASCII character 31" line (this should arrow down to next test version).
    A report window comes up in ARD with this error message:
    86:104: execution error: System Events got an error: 31 doesn't understand the ASCII character message. (-1708)
    This used to work perfectly, but now I can't get ASCII 31 (or arrow down to work). The real killer is that other techs in my school district have eMacs running tiger with same commands that work (some have to arrow down 16 times to get to correct test version). The other commands (like command 1 and returns, command n) all work fine! Hate to have to touch 80 machines each day to select proper test version when we log in.
    Any Suggestions????

    Try this form of the line:
    keystroke (ASCII character of 31)
    That's worked for some people. Hope it works for you. If it doesn't work as given, try without the parentheses.
    Regards.

  • Calling Java from Delphi via JNI

    Hi all. I've got a J2EE application, and I'm trying to write a Delphi client for the server. More specifics:
    Server and test client running in Win2000 SP4.
    Server running in JBoss (JUnit test cases have successfully connected to the server)
    JDK 1.4
    I'm using some Delphi files from JEDI which allow me to load/access a JVM via JNI. So far, I've been able to:
    1) Create a Properties object.
    2) Populate the Properties object with String values (making sure to use NewStringUTF to pass into the Properties method
    3) Find my java client classes which facilitate opening a connection.
    However, when I attempt to call the method on the object which actually creates the connection, I get an Exception.
    My immediate question is how do I see what the Exception is? I have an Exception object, but ExceptionDescribe doesn't product anything, and I'm having trouble finding any details about the Exception (what type of exception, what the Message or Call Stack is). At the moment, something's wrong but I can't see what. And I'll have no chance of fixing it if I don't know what the problem is.
    Thanks for any help,
    Ed

    I use some code for solving this task (in real project with Delphi 6.0 & Java 1.4.1).
    May be, it will help.
    procedure TJavaInterp.CheckJNIException(Message : string);
    begin
    if JNI_ExceptionCheck(JNIEnv) = JNI_TRUE then
    begin
    JNI_ExceptionDescribe(JNIEnv);
    JNI_ExceptionClear(JNIEnv);
    raise Exception.Create(Message);
    end;
    end;{ TJavaInterp.CheckJNIException }
    procedure TJavaInterp.HandleException(excpt : jthrowable);
    var
    Msg: string;
    ESyntax : Exception;
    CauseName : WideString;
    Tag : OleVariant;
    begin
    if JNI_IsInstanceOf(JNIEnv, excpt, FclsCommonSyntaxError) = JNI_TRUE then
    begin
    ESyntax := Self.BuildSyntaxException(excpt);
    JNI_DeleteLocalRef(JNIEnv, excpt);
    raise ESyntax;
    end;
    Msg := Self.GetMessage(excpt);
    if JNI_IsInstanceOf(JNIEnv, excpt, FclsNPScriptRuntimeException) = JNI_TRUE then
    begin
    CauseName := Self.GetCauseName(excpt);
    Tag := Self.GetTag(excpt);
    JNI_DeleteLocalRef(JNIEnv, excpt);
    raise NPScriptHelper.BuildNPScriptRuntimeException(Msg, CauseName, Tag);
    end;
    if JNI_IsInstanceOf(JNIEnv, excpt, FclsHaltException) = JNI_TRUE then
    begin
    JNI_DeleteLocalRef(JNIEnv, excpt);
    raise Exception.Create(Msg);
    end;
    Msg := Self.ToString(excpt);
    JNI_DeleteLocalRef(JNIEnv, excpt);
    raise Exception.Create(Msg);
    end;{ TJavaInterp.HandleException }

  • Send UNIX command as root

    So I read in this thread  how to send a UNIX command via ARD as root.
    My question is why does ARD allow you to use root without entering a password?

    Because you're already authenticated to the client workstation as an administrator user.

  • How do I run a unix command to quit ARD if it is running on a remote server I am trying to access?

    how do I run a unix command to quit ARD if it is running on a remote server I am trying to access?

    killall "Remote Desktop"
    Regards.

  • Known problems or limits regarding accessing BDB with Java via JNI

    Hi,
    we are currently in an evalutation phase and are planning to use BDB (C|JE) as back-end for a queueing system. This system is written in Java. One key requirement is high availability of the data hold in the back-end. We need the guarantee, that no data is lost, e.g. data added after checkpoints. The throughput is expected to be quite high (> 10.000.000 records hold within one single BDB-environment (we would use n parallel BDB-envs inside the service).
    So i'm wondering about using JE or DB... The former doesn't provide a replication system but is a 100%-pure Java implementation, the latter is written in C and accessed via JNI, which adds some overhead and maybe instability issues but comes with an integrated replication system. JE would require us to develop an in-application replication system or to use a DFS for HA or something like that.
    Are there any known issues regarding using DB with Java via JNI? Or any other hints?
    TIA,
    Dirk

    Silly me, I forgot to mention that a null return value means that an exception was thrown so you should get that and print the value (although I suspect it will be "class not found").

  • Can't Set Remote Login OFF via Send Unix Command systemsetup

    Trying to use the System Setup->Remote Login template in ARD to turn off Remote Login (SSH) in Sharing panel of System Preferences on Mac that is administered through Apple Remote Desktop.
    In Apple Remote Desktop (ARD), I select the client machine, then choose "Send Unix Command..." from the "Manage" menu. In resultant window, I pick "System Setup->Remote Login (SSH) from the "Template" drop down box in the upper right. That populates the upper window with Unix commands. I edit/change the "on" to "off" and tell the dialog to Run command as User: root, then click on "Send" button.
    Progress bar goes forever with no change.
    I can turn off Remote Login via ARD by controlling each client machine via an ARD WINDOW, then navigating to the Sharing Preference pane, but that process is tedious when performing for multiple client Macs.
    Strange, but I CAN use the "Send Unix Command..." outlined above to turn ON Remote Login, and get the status of Remote Login ("systemsetup -getremotelogin"). Just can't turn OFF Remote Login (quickly/efficiently).
    man systemsetup suggests I need to write the command as "setremotelogin -f off" but that failed with an improper command syntax error.
    Thoughts?

    It’s waiting for you to type a confirmation. If you run this command on the command line normally, you’ll see the message:
    Do you really want to turn remote login off? If you do, you will lose this connection and can only turn it back on locally at the server (yes/no)?
    Use this command instead:
    systemsetup -f -setremotelogin off

  • Unix command to update Microsoft Office 2008 via ARD

    I'm looking for a unix command I can send via ARD to update Microsoft Office 2008. It just needs to install all updates and then restart. Kinda like apple's software update one: softwareupdate -i -a; shutdown -r now

    Why go through all the trouble of trying to do it in Unix.  Apple and Microsoft made it a LOT easier.
    Just download the update from Mactopia
    Open the .dmg
    (for convience and ability to have it stored) Drag the Update from the Microsoft folder that opens up and put the update on your desktop
    In ARD Select what computer(s) you want to install the update in
    Use ARD Install function to install the update
    Go have a cup of coffee and a donut while ARD does the install.
    You do not even have to do a restart.  Microsoft uses a different icon for the update but it still is a package file operation.

  • Method to restart Oracle Apps 11i OPP via Unix command line

    Hi All,
    Does any one knows if there any way to restart Oracle Apps 11i Output Post Processor (OPP) via the UNIX command line?
    Thanks

    Oracle-User wrote:
    Do you recommend that I set the profile option Concurrent: OPP Response Timeout to a higher value instead of increasing OPP Processes from 1 to 2? Yes.
    I'm thinking that increasing OPP Response Timeout to a higher value will not solve our issue as it seems that once we get our first OPP Timeout error, all of the requests that need the OPP fail. We've had this occur on a Saturday, which is a day where the volume of jobs that need the OPP is very low. The error you are getting is related to the timeout and it has nothing to do with the number of OPP processes you are running on. Please set this profile option and check then (after you bounce the OPP).
    Thanks,
    Hussein

Maybe you are looking for

  • Documents now opening in pse editor photoshop instead of a PDF in Adobe reader?

    why is all of my documents now opening in pse editor photoshop instead of a PDF in Adobe reader?

  • X3-00 instant messaging -chat not pre-installed

    Recently bought x3-00, but nokia instant messaging (chat) is not preinstalled in it.. any way i can install it??  when i go to the nokia website it says "nokia messaging is preinstalled in your phone"... any suggestions?? thnxs

  • [SOLVED] Multiple sound cards don't work with Arch

    Before you post, make sure you do not list any of these programs that I should use, to configure everything: alsamixer alsaconf kmix xfce4-mixer edit: I need to specify what my default sound device is as I have 2 different sound cards, a Logitech Cle

  • Full signal strength but unable to connect to the internet

    I just got my ibook G4 about a month ago and have only been able to access the internet for about 2 weeks on and off. After I set up my wireless linksys router I was able to connect right away and it was fine. Then about a week or so after using it w

  • 9600Pro ATI and KT6

    I just did a clean install of XP-SP1 to my 2500+ KT6 board with an ATI 9600PRO video card. All the bios settings for AGB are default. If I install the 3.8 drivers for my card, the machine locks up, displays wacko colors, corrupt test boxes, ets. Just