Help Please: How to invoke unix command lines from java?

I have read past topics. Those are really helpful, but I still haven't got my job done. I tried the following:
String command1 = "ls -la > ls1.txt";
Runtime.getRuntime().exec(command1);
String command2 = "tcsh -c ls -la > ls2.txt";
Runtime.getRuntime().exec(command2);
String command4 = "cp keywords.txt copyversion1.txt";
Runtime.getRuntime().exec(command4);
String command5 = "tcsh -c cp keywords.txt copyversion2.txt";
Runtime.getRuntime().exec(command5);
String command6 = "tcsh -c 'cp keywords.txt copyversion3.txt'";
Runtime.getRuntime().exec(command6);
Only "command4" works. Any input will be greatly appreciated.

Thank you very much Gautam. Your solution certainly works. If you don't mind, I would like to ask you (or anybody who is willing to answer) something else. I am trying to run other types of unix command lines as well. I thought that the format you gave would work for everything. But it doesn't seem so:
String command1[] = {"tcsh", "-c", "ls -la > ls1.txt "}; // this works as you suggested
Runtime.getRuntime().exec(command1);
String command12[] = {"tcsh", "-c", "lynx -dump http://www.yahoo.com > webpage.txt"}; //working fine.
Runtime.getRuntime().exec(command12);
String command10[] = {"tcsh", "-c", "ngram-count -text keywords.txt -lm LM10 &"}; //doesn't work
Runtime.getRuntime().exec(command10);
String command[] = {"tcsh", "-c", "/u/drspeech/sun4/bin/ngram-count -text keywords.txt -lm LM0 &"}; // doesn't work
Runtime.getRuntime().exec(command);
String command13[] = {"tcsh", "-c", "ngc -text keywords.txt -lm LM13"}; // doesn't work
Runtime.getRuntime().exec(command13);
String command8 = "ngram-count -text keywords.txt -lm LM8 &"; //doesn't work
Runtime.getRuntime().exec(command8);
String command9 = "/u/drspeech/sun4/bin/ngram-count -text keywords.txt -lm LM9 &"; //doesn't work
Runtime.getRuntime().exec(command9);
I tried "commandd1" and "command12". Those worked fine. No problemo. However, there's someting else I need to get done for my job; that is "command10". But it just didn't work. I thought maybe, it's because "ngram-count" is not part of the standard UNIX commands. So, I thought I might just add another alias for it in the ".cshrc" file and call it "ngc" instead. Then I tried to call the alias "ngc" instead. But it didn't work also. Then I thought, maybe, I should call it by referencing it from its original directory "/u/drspeech/sun4/bin/ngram-count". That didn't work either. I tried a couple of other combinations. None worked. I would really like to see how to solve this.

Similar Messages

  • How to execute unix command line from cocoa?

    how to execute unix command line from cocoa?
    for example, if I want to call "ping" from cocoa, how should I do it? and how can I obtain the return value?
    thank you.
    Power G5 Quad Mac OS X (10.4.3)

    The following article may also help:
    http://cocoadevcentral.com/articles/000025.php
    Mihalis.
    Dual G5 @ 2GHz   Mac OS X (10.4.6)  

  • Invoke a command-line from java

    Hello!
    I wonder if there' s a way to invoke a command or running an .exe file from java code.
    10X,
    Yaron

    Sure, using the exec method in the class Runtime. You have to be careful with it though...
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Invoking unix shell scripts from java?

    Hi,
    could someone explain to me how one wuld invoke unix shell scripts from java.
    Also, could you invoke Visual Basic scripts from java.
    Finally, could you do this from an EJB?
    thanks for any help....
    sudu

    I just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
    --Ian                                                                                                                                                                                                                                                                                       

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Looking to run unix command line from Finder

    I want to run a unix command directly from finder. Kind of like using command-G to "Go To Folder".
    If a current method isn't supported, I noticed that Terminal.app has a shortcut for "New Command" using command-N. What would be the right way to create a keyboard shortcut in Finder that would call Terminal->New Command?
    Thanks

    You might use a third-party macro expansion utility that permits creating keyboard macro shortcuts. Examples include QuicKey or iKey. There are also several text expansion utilities that also allow attaching keyboard shortcuts such as TextExpander or Typinator. The above can be found at VersionTracker or MacUpdate.
    You can also create an AppleScript using the Do Shell Script command. The resulting compiled script can be attached to an Automator action. I don't know if you can attach a keyboard shortcut but you can add an Automator action to the Services menu and to the Finder's contextual menu.

  • Execute command line from Java

    I have an easy one for you!
    I would like to know how I can execute a command line from my java code.
    The only thing I want to do is to launch a html page with the default browser in my computer when I press one button of my java application but I dont know wich class I should use to do it. My application will already know what is the file name.
    Thank for your help
    Eric

    Javaworld has some source code that does this:
    http://www.javaworld.com/javaworld/javatips/jw-javatip66.html

  • How to include a parameter executing a command line from java??

    Hey
    I've a problem It's very single for you: this consists in execute a command from java
    in this case the command is : runas but I've tried nd is good but I can´t include the password.
    This is due to the sintaxis is :
    runas /user:127.0.0.1\Administrator cmd
    The first command is execute but.. the problem is it show the input for the password.
    And the password is not let including in the command line
    How can I do that? Please help me is very urgent.
    Any help will be very appreciated.
    Thanks in advance.
    Best Regards.

    DAnt. wrote:
    what is the name of the correct forum which I must visite? this is because I couln't found the correct forum.You will not find it on the Oracle website
    I expect your prompt reply,help me!http://tinyurl.com/yak89nc

  • Using Unix command lines in java code

    I was wondering if there was a way to run a unix command in java code. I know in C++ there is popen, but i don't know of a way in java. The command i need to run is the whois "domain name" command. Any help would be great!
    jarad

    try something like this:
      public static String whois(String domain) throws IOException {
        BufferedReader is = null;
        Process p = null;
        String result = "";
        p = Runtime.getRuntime().exec("whois " + domain);
        is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while((line = is.readLine()) != null)
          result += line;
        return result;
      }

  • How to invoke a jsp page from java which does not use Servlets?

    Hello,
    I am working in Documentum. I am trying to invoke a jsp page from another java page which does not use Servlets.
    I tried doing this by just instantiating the java class related to the jsp page from my present java class.In my java class related to the jsp page, I have defined onInit() and onRender() methods.
    Now, I am trying to call the jsp page from my present java class by just instantiating the java class related to the jsp page. This throws a java.lang.NullPointerException.
    Any comments or suggestions on this.Any help would be appreciated.
    Thanks,
    Ranjith M.V

    RanjithM.V wrote:
    Hello,
    Thanks for the reply. One important thing I forgot to mention. I am also using xml component.And?
    As this is the standard way used for coding in Documentum, I do not want to use Beans.Well, JSP's should, in and of themselves, contain no functional code. It should all be only display.
    Without that is it not possible?What did I say? I said,
    masijade wrote:
    It is possible, but I very, very, very, much doubt, that it would be worth the effort.And, if you don't know how, a forum is not truely going to be able to help you implement it (at least not in less than a few years time, at which point it would be outdated).
    >
    Appreciate your understanding and help.
    Thanks,
    Ranjith M.V

  • DOS 11g SOA have the Locator API's - How to Invoke a BPEL process from Java

    In BPEL 10.1.3.1, a java client could use the "Locator" API's to look up a BPEL service and invoke it directly from Java,
    Is that still present in SOA 11g ? Or is there another way to look up the BPEL process ...
    Here's an example of the 10g BPEL Service locator facilities :
    Get the BPEL service locator. This is retrieved as follows:
    loc = new Locator(domain, domainPassword);
    The initial installation BPEL domain is "domain" and the initial password is "bpel". We then use the locator to get the delivery service. We could also use the locator to retrieve the workflow service.
    IDeliveryService svc = (IDeliveryService)loc.lookupService(IDeliveryService.SERVICE_NAME);
    Now we have the delivery service we can "deliver" requests to the BPEL process. To do this we first need to create a new message.
    NormalizedMessage msg = new NormalizedMessage();
    String content = "<SyncHelloWorldProcessRequest xmlns=\"http://antony.blog/SyncHelloWorld\">"+
    "<input>"+
    name+
    "</input>"+
    "</SyncHelloWorldProcessRequest>";
    msg.addPart(msgPart, content);

    Can you please tell me how to include adf binding.ws in composite.xml ? My composite.xml for your ref:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SOA Modeler version 1.0 at [11/1/10 5:41 PM]. -->
    <composite name="BPEL2"
    revision="1.0"
    label="2010-11-01_17-41-11_593"
    mode="active"
    state="on"
    xmlns="http://xmlns.oracle.com/sca/1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
    xmlns:ui="http://xmlns.oracle.com/soa/designer/">
    <import namespace="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1"
    location="BPELProcess1.wsdl" importType="wsdl"/>
    <service name="bpelprocess1_client_ep" ui:wsdlLocation="BPELProcess1.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.interface(BPELProcess1)"/>
    <binding.ws port="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.endpoint(bpelprocess1_client_ep/BPELProcess1_pt)"/>
    </service>
    <component name="BPELProcess1">
    <implementation.bpel src="BPELProcess1.bpel"/>
    </component>
    <wire>
    <source.uri>bpelprocess1_client_ep</source.uri>
    <target.uri>BPELProcess1/bpelprocess1_client</target.uri>
    </wire>
    </composite>
    Eric, when I select the BPEL wsdl file in "Create Web Service Data Control" wizard, immediately I am getting the error. When I click 'OK', the 'Service' dropdown is disabled and blank in the wizard.
    Thanks for pointing to the sample application URL. But it is built in jdev 10g. Can I migrate it to 11g?
    Thanks both of you!

  • To execute command line from java programmin

    Hi,
    I need to execute a command line like ping command from java applications can any help me on this. Thanks in advance.

    Runtime.exec
    Also read: When Runtime.exec() won't: Navigate yourself around pitfalls related to the Runtime.exec() method

  • How to run unix shell script from java web applet

    hi all
    i have created one java applet. my apache web server is on unix server.
    i have created one shell script in same directory where my .class and .htm files reside...
    how to run this shell script from applet? it should search this .sh file on server and not on the client browser machine...
    thanks in advance

    I suppose you could make the shell script into a CGI, configure the server to execute CGIs, and then make the applet open the URL of that CGI.

  • How to run Discoverer 10g report from unix command line

    Hello Experts,
    I am aware that discoverer report can run through command line using "dis51usr.exe /connect username/passward@connection_string /opendb "DISCOVERER.<<report name>> /export xls"".
    Can we run discoverer 10g report (stored in database) from server location / unix command line? Is there any command?
    Please assist. Thank you.

    Hi Tamir,
    Can you please mention from where we have to execute/run these commands? After setting enviornmental variable, are these commands run from any location or we have to go to particular server location and then execute (ex. from directory BI or else).
    Thank you.

Maybe you are looking for

  • "iTunes has stopped working" during every startup

    Every time I try to open iTunes, it says iTunes has stopped working. When I open it, it actually works for a good two seconds before it crashes. I've tried to play one of the songs by double-clicking one of the albums and it starts to play until it c

  • Upgrade 640 to 700: ERROR is BI : com.sap.ip.bi.sdk.dac.connector

    Hello Experts, I am doing the java system upgrade from NW04 to NW04s SR2. During the "Deploy Online" phase, the upgrade is failing due to below error EAR file uploaded to server for 31ms. 07/11/10 05:34:18 -  ERROR: Not deployed. Deploy Service retur

  • Tolerance Limit for GRN.

    If I have maintained the upper tolerance limit in PO. And if the PO will have no open items, then system will allow to make the GRN of extra quantity(within this tolerance limit). Is there any configuration for this?

  • Captivate 7 Help for creating Variables and Results

    Hi there, I'm currently trying to create a results page from the collection of the users selections in a survey that consists of radio buttons that would rate the users skills from 5 different levels starting from "unsatisfactory" to "Outstanding". W

  • Error in accounting entries in depot process

    Hello all 1. At the time of stock transfer to depots, excise entries are correctly generated and cenvat sales clearing account is getting debited. 2. At the time of billing from depot to the end customer, sales (revenue account) is wrongly credited w