Platform neutral Runtime commands

I'm using the Runtime class to issue a command to the OS. For NT it works like this:
String[] commandArgs = {"cmd", "/c", command};
proc = Runtime.getRuntime().exec(commandArgs, envp, file);
I need to know what the comandArgs would be for a unix based os?
And, I am looking for advice on how to determine the actual OS at runtime so I can issue the platform specific commandArgs.
Thanks

First of all, I belive there are no OS specific command args... they are passed to command by possition and they are interpreted by programmer based on some best practices. In unix you can meet params without any preceding chars like:
ps aux
switches like
ls -la
modern switches like --verbose etc...
You can determine OS filesystem path separator using java.io.File static public field "separator", try to execute code like this:
Properties props = System.getProperties();
Enumeration en = props.propertyNames();
while(en.hasMoreElements())
   System.out.println(props.getProperty((String)en.nextElement())); You will get some info about platform and runtime at all

Similar Messages

  • Unable to restart the Microsoft Software Protection Platform service from command line - Win81 MS Office 2013 SP1

    I'm unable to restart the Microsoft Software Protection Platform service on a Windows 8.1 laptop for MS Office 2013 SP1 (32-bit) using the following command:
    cscript ospp.vbs /osppsvcrestart (issued from C:\Program Files (x86)\Microsoft Office\Office15)
    When this is run, a window appears with the title ospp.vbs and the text "Error: The Software Protection Platform service is not installed"
    I verified that the service is installed in services.msc, and was able to manually stop and restart the SPP service in the Services console without issue.
    The command runs correctly when restarting the MS Office 2013 SPP on Windows 7 devices.
    Has anyone else seen this or have a solution for it?
    The reason that I am attempting to restart the service from the command line is because this command is part of a script to change the KMS server IP Address used by OSPP prior to software activation.
    The only other options that I have at this time is to ask the users to reboot, or manually force a reboot.  This is both time consuming and disruptive to the users.
    The Fix It tool to remove MS Office 2013 was run, and the MS Office 2013 software was successfully reinstalled after a reboot.  The software was successfully activated.  When the command was run, it produced the same exact error.

    Hi,
    I am able to reproduce this on my own machine, but in my case, I don't see the specific service running in the Services console. 
    I would like first confirm that whether you've the right service running on your Windows 8.1 system. The display name of this service should be "Office Software Protection Platform", service name is "osppsvc".
    You can also check this by going to below path where you should see the executable file (OSPPSVC.EXE) if the service is installed on your system (in my case, the folder is empty):
    C:\Program Files\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Runtime + Command window

    Hi,
    I am trying to execute Runtime.getRuntime().exec() command on click of a button. It works fine, but the problem is that i get a command window when the command is executed. Is there any way to make the command window not to appear?

    Duplicat thread, answer here
    http://forum.java.sun.com/thread.jspa?messageID=4034633

  • Problem with executing runtime command

    Hi everyone,
    when i execute the following command on a command line it is done within one minute:
    d:\Applikationen\usr\local\wbin\sed.exe -e "/^#/d" D:\dokumente\file_1.txt > D:\dokumente\file_2.txtUnfortunately when i call the same command from within my application then nothing seems to happen:
           Runtime rt = Runtime.getRuntime();
           System.out.println("Runtime obtained");
           Process p = rt.exec(cmd);
           System.out.println("Command executed");
           int ex = p.waitFor();
           System.out.println("Exit code "+ex);

    Read this
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How can i wait util runtime command complete

    hi all
    i am creating database through runtime exec and the created database
    is going to use further, i need wait until the database created.
    After the created database i want use for inserting,updating etc, data
    into tables.( i have code after runtime exec, that code only is going
    to use insert data. etc)
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("/bin/bash misc/createDB.sh");thanks
    daya

    If I understand right, you need to wait till the createDB.sh script has not finished executing.
    You can add a line of code after which goes,
    proc.waitFor();
    This will cause the program to wait till the previous process has completed execution.

  • Developing a platform: better to command or provide

    I'm developing a platform that will provide services to a set of classes (plugins) that must extend from an abstract base class. One of the services is a database connection to a common database that alot of the plugins would probably want to use, like the employee database. This is to keep the total number of connections hitting the database to a minimum.
    In general would it be better for the platform, through the abstract class, require the plugin to support a setConnection(Connection empConn) method that the platform would call or pass a call back reference to the platform and let plugin ask for the common connection if they want it as in public Connection getEmpConn()Thanks,

    If you migrate a 1.2 Swing app to a 1.1.8 platform, you will also need to download the swing package for 1.1.8, and change all the source code imports from javax.swing.* to com.sun.java.swing.*.
    Otherwise your Swing code won't compile. There was a package name change for Swing between 1.1 and 1.2. The other poster gave details on how to have Collections run in 1.1
    Security might be an issue - J2 upgraded the whole security thing. Only way I know around this is to delete the offending security code to run in 1.1.
    Otherwise a 1.2 program should run OK in a 1.1 environment.
    Cheers

  • Executing batch files from websevice using ODI OS Command

    Hi,
    Is it possible to execute the batch files using odi os command from webservices.
    We have developed a webservice, which passess some parameters to one batch file and after that we executing the same batch file in package using odi os command. In opeartor is showing as running, it never ends.
    But if we run the same package from designer, it is executing successfully. Also the same web service is working fine for executing non batch scenarios.
    what could be the problem??
    We got one possible reason for failure...
    For executing the batch from web services, we need read and executable permissions on the drive where batch sits.
    We are logging into ODI using SUPERVISOR. How to give the permissions to SUPERVISOR as we are having windows authentication.
    Edited by: Naveen Suram on Dec 17, 2009 8:07 PM
    As a work around, can we use ODIOSCommand instead of OS Command. But it is asking for starting event? Whether both the commands does the same functionality??
    Edited by: Naveen Suram on Dec 17, 2009 9:08 PM

    From the FAQ:
    2. How do you launch an external program on a Microsoft Windows platform from a program developed on the Java [tm] programming language?
    The following will launch notepad in Microsoft Windows NT:
    Runtime.getRuntime().exec("cmd /c notepad.exe");
    To launch a program in Microsoft Windows 95/98 use:
    Runtime.getRuntime().exec("c:\\windows\\notepad.exe");
    The Runtime class allows interaction between a program and its environment. The first string command instructs the command line interpretor, cmd to open up the calculator application.
    The exec() methods do not use a shell; any arguments must have the full pathname to the shell as well as the command itself.
    For example, to run a shell on the UNIX� platform, type:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("/usr/bin/sh -c date");
    To run a batch file under Microsoft Windows 95/98:
    Process p = rt.exec("command.com /c c:\\mydir\\myfile.bat");
    To run a batch file under Microsoft Windows NT:
    Process p = rt.exec("cmd /c c:\\mydir\\myfile.bat");
    where 'cmd' and 'command.com' are the command-line interpreters for Microsoft Windows machines.
    The Runtime.exec() methods might not work effectively for some processes on certain platforms. Special care should be taken with native windowing, daemon, WIN16/DOS process or some shell scripts.
    regards,
    jarshe

  • Closing programs thru runtime?

    Hi all,
    i've written a program that fires up RealPlayer using the runtime command RunTime.exec(program location). Works fine and all. Now i want to be able to close RealPlayer from within my program. This doesn't seem so obvious. I'm using it within the windows environment and the program isn't platform independant anyway so suggestions relating to shutting down within windows are fine.
    Any suggestions woul be most appeciated,
    Neil

    Unfortunately, that kills the process but not any programs that may have been started during that processes lifetime. Thanks for the response!
    Neil

  • How to wait till the end of DOS program started using Runtime.exec(cmd)?

    In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other batch file start.bat.
    The piece of code which I am using is:
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    For this piece of code it starts the first batch program(i.e, call.bat) in a command prompt and immediately it starts the second batch program (i.e, run.bat) in another command prompt. So it runs both the batch programs simultanesously. But what I wanted is that my program should wait till the first batch is executed and then start the second batch.
    Please tell me how to wait between these two runtime commands in JAVA
    With regards,
    C.Chenthil.
    -------------------

    Hi everybody thanks a lot.
    I got a solution from another forum. Kindly find the solution
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat"); is the switch that served my purpose.

  • Executing a runtime.exec statement from an ejb

    Hi all,
    relativly new to j2ee. I need to use the runtime.exec command to uncompress a set of files from an ejb.
    So far, ive tried that and even the most basic commands like
    /usr/bin/ll *
    and i don't get any response back other than: exit value = 2
    when executing:
    Runtime runtime = Runtime.getRuntime();
    // Process proc = runtime.exec("/usr/bin/uncompress "+this.localFileStore+"*.Z");
    Process proc = runtime.exec("/usr/bin/ll * ");
    // put a BufferedReader on the ls output
    InputStream inputstream = proc.getInputStream();
    InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
    BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
    // read the ls output
    String line;
    while ((line = bufferedreader.readLine()) != null) {
    System.out.println(line);
    // check for ls failure
    try {
    if (proc.waitFor() != 0) {
    System.err.println("exit value = " + proc.exitValue());
    catch (InterruptedException e) {
    System.err.println(e);
    No output from the buffered reader. Any one have any ideas as to why i cannot execute any runtime commands? This is also related to the thread i created where i'm looking for a java library for uncompressing a unix compressed file (unix compress = *.z and not zip or gz files). I think my only two options are to either use the runtime to uncompress these files or.. use some java library to uncompress these files. Let me know if anyone can offer any hints/helpfull comments/libs
    Thanks a bunch

    I might be wrong on this one, but I believe using Runtime.exec() would generally be frowned upon when invoked from an EJB. The reason? EJB implies a remote call. Can you guarantee that a given native process or service will be available on all possible remote nodes that the EJB might be deployed on? Maybe. Can it actually be achieved? Yes. Is it in the spirit of EJB? Probably not.
    - Saish

  • Runtime.exec2

    how do we let the runtime command know which argument is an input and which argument is an output?
    argh... help me please.

    how do we let the runtime command know whichargument is an input and which argument is an
    output?
    There is no such thing like an output argument.
    The only way for the exectued comand to return
    something is to write something to stdout and
    stderr and to return a result (errorcode).can now. thanks for the tip andih!

  • Executing System commands

    Hello,
    I have a scnerio where I have to execute a Shell command like
    "ping 192.168.0.26" but I think in Java 1.4 the System.execute() method is
    deprecated. I used the Runtime command like this
    Process p;
    p = Runtime.getRuntime.exec("ping 192.168.0.26");but it shows me nothing on the console window. I want the output to be in the console window. How can I do that???

    Now I here is what I was trying before
    import java.io.*;
    public class test{
         public static void main(String[] args){
              Process p;
              String cmd = "ping 192.168.1.1";
              OutputStream out;
                           try{
                                 p = Runtime.getRuntime().exec(cmd);
                                   catch(IOException e){
         e.printStackTrace();
    }What else should be added to it

  • Cannot execute sapevt.exe on a Windows platform

    Hi
    for some reason I cannot get the sapevt.exe program to raise an event in SAP when running on a Windows platform. The command line I'm using is :
    D:\usr\sap\<SID>\SYS\exe\uc\NTAMD64\sapevt.exe event=EVENT_NAME -t2 name=<SID> pf=D:\usr\sap\<SID>\SYS\profile\DEFAULT.PFL
    It doesn't write an dev.evt trace file either. Also I'm using inside a VB script.
    I can raise the event from within SAP Tcode SM62 and it runs fine in a Unix environment with slightly different parameters of course
    Anybody help please.
    I've looked at notes 802172 and others and tried all the suggestions within.
    Thanks
    Regards
    Steve

    I have the following command defined in SM69 that works on our Windows-based SAP systems:
    Operating system command = sapevt
    Parameters for operating system command = ? -p ? -t pf=$/DIR_INSTALL/\profile\default.pfl
    Additional Parameters Allowed is checked
    What not try and define that and then trigger it inside SAP itself? It might clue you in as to what the issue might be. The input parameters are the event name and then any additional parameters when triggering the event.
    Brian

  • Supressing Dos window on executing system command

    Hey,
    is there any way to supress the dos window when I call a system dependent .exe or bat file?
    AND
    is there any way to run a .exe file as a background process so that no window of it pops up?
    I use the Runtime.exe() to execute the system command but I'm annoyed by the dos windows it opens up.
    Any help highly appreciated.

    This is an AGE OLD Issue which Sun keep burying. By burying I mean it has been the top of their bugs/requests list many times. They just decide its closed without making any such fixes. The community is not pleased with Suns actions in this respect, blowing off their highest rated request.
    Answer:
    If you start your program with java.exe, then you wont get that window when you do runtime commands. If you start with javaw.exe, you will. They are blaiming it on M$ but most feel its just a silly Sun position and lame attempt to put somethign on M$ that is not really on M$. Sun can do it but they feel their solution is unstable. Most people have ended up making .exes to replace java.exe to get rid of that hideous console window. JBuilder has an interesting (but not my type) solution.
    If you search the top 10 bugs/ requests this one has likely resurfaced as Sun keeps erasing it, but the people keep voting it back to the top...

  • How can I load PCL font using command line?

    We have a software that requires a signature font to be uploaded to the printer beforehand.  if the printer power cycles, the font is lost and paper is wasted.  This usually happens when a brown out occurs overnight.
    Our font vendor has a command line windows software that can upload the font to the printer.  It costs 100.00. 
    I'd really love to find a way to upload this file using linux.  The page is generated on linux so i could incorporate the command into that process.
    Anyone know of free software to do this on linux or windows?  or maybe programming documentation?

    i think i found the answer on another site
    http://mdn.morovia.com/kb/Download-Select-Remove-PCL-Fonts-10002.html
    Configuration 2: Network Printer Server
    When the printer is connected to a TCP/IP network directly, the best method is to send commands through lpr command. A TCP/IP device may be identified with a full qualified DNS name, or an IP address. In our test lab, we assigned our network printer a fixed IP address 192.168.1.22, and we use this address in the examples below. Inlpr manual page, it is also referred as Printer Name.
    Another name you will need is Queue Name. The queue names are names assigned to the “processors” in the print server. Many print servers and network printers hardcode their queue names. Some allow you to define your own queue. On HP JetDirect printer servers, the raw PCL queues are named as raw, raw1, raw2 and raw3. In this article we use rawas the queue name.
    Note thatlpr command only accepts 1 file at a time. However, the step1 and step2 commands must be sent in one stream, otherwise the printer discards them altogether. As a result, you will need to merge those three files into one first. On Windows, you can use copy command:
    copy /b C80D.txt +mrvcode39_4pitch.sfp +c5F.txt total.bin
    On Linux/Unix platforms, use cat command:
    cat c80D.txt mrvcode39_4pitch.sfp c5F.txt > total.bin
    Now we can send these files (Windows):
    lpr -S 192.168.1.22 -P raw -ol total.bin lpr -S 192.168.1.22 -P raw -ol data.txt
    You need to replace the IP address, the queue name and the file name with the appropriate ones in your environment.
    On Linux/UNIX platforms, things are more complicated. The configuration varies from platform to platform. Generally you need to set up the printer first. On RedHat Linux, this can be done using printtool. You assign a printer name (queue name) in the configuration, and you use this name in lpr command. Assume that the name is HPPrinter, the lpr command on RH Linux becomes:
    lpr -P HPPrinter -o raw total.bin lpr -P HPPrinter -o raw data.txt

Maybe you are looking for

  • How can I delete saved messages from my iphone 5s to be able to update it?

    I have needed to update my Iphone 5s from the past 2 updates but it says that I have 4.2 GB of saved messages.  I don't know where to go to delete them.  I delete regular messages from my phone daily so I'm not sure what is being saved and where. Tha

  • First day of week in WebAccess and CalendarPublisher

    Hi, after upgrading from GW8.02 to GW2012SP1 the first day of week in WebAcc and CalPub is Sunday again. Under GW8.02 I had configured the first day as Monday (in a configuration file) Unfortunately I don't remember which file it was? Any ideas? Kind

  • My HDX X18 HDD upgrade/ replacemen​t

    my HDX X18-1050EF hdd originally came with 2 250gb/ 5400 for a total of 500gb. Im about to upgrade the primary hdd to 250gb/7200 I don't need more space, but a slightly faster hdd. Not faster like an SSD. but i don't know if the computer will be able

  • Relating to Foreign currency valuation

    what are the general entries generated when we valuate the foreign currency. when its gain / loss i want the two entries so please provide me. And how we update the Valuation fields of exchange rates every month.

  • Conversion of a file with 2 converters in UCM / IBR?

    Hi Folks, This might be a basic question, but would be helpful in making a key decision in our use case. Can we configure 2 conversions for a single file format? As we would like to convert each incoming jpeg file into PDF as well as getting the imag