Calling linux command line in Java

Hi guys,
I met a problem about calling linux comand in java program.
In linux, I type :
similarity.pl -type WordNet::Similarity::vector -file /home/csunix/fzsu/exam.txt
it returns:
Loading WordNet... done.
Loading Module... done.
good#a#1 nice#a#1
good#a#1 nice#a#1 0.885813537770033
dog#n#1 cat#n#1
dog#n#1 cat#n#1 0.712603873475428
good#a#6 nice#a#1
good#a#6 nice#a#1 0.822428178005622
From above, we can see that it works well, similarity.pl is a perl program for computing similarity between two concept, and -type and -file are the parameters.
Now I want to use java to call these command, and here is my code:
public static void main(String[] args) {
try{
String command="similarity.pl -type WordNet::Similarity::vector -file /home/csunix/fzsu/exam.txt";
Process p=Runtime.getRuntime().exec(command);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=null;
while ((line=br.readLine())!=null){
System.out.println(line);
}catch (IOException ex){
ex.printStackTrace();
But noting is print out. I also add the full path for similarity.pl, like /home/csunix/fzsu/similarity.pl in the variable "command", but still the same.
I also change variable "command" to a string array in this way:
String command[]={"/home/csunix/nlplib/WordNet/2.1-F7/perl/bin/similarity.pl",
                    "-type","WordNet::Similarity::vector","-file","/home/csunix/fzsu/exam.txt"};
Again, I get nothing from it.
Can anyone point out how to solve this problem?
Thanks,
Joe

Crosspost.
Don't do this if you want help!
This question is answered on "New to Java".

Similar Messages

  • How to make system call to execute command line in JAVA?

    Hi,
    I am new in JAVA. How to make system call to execute the following command line in JAVA in LINUX environment.
    rpm -qa jdkIn C programming, use as such:
    system ("rpm -qa jdk");
    How about JAVA?
    Thanks.

    Runtime.getRuntime().exec. But first read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Downloading Java 6 on Linux command line with wget

    Hello,
    I'm trying to download Java 6 on the Linux command line, because my GUI interface is not working.
    So I'm using the Linux wget command for this.
    I tried the following
    wget -r -O jdk.bin http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u4-linux-i586.bin?BundledLineItemUUID=_09IBe.lhyoAAAEYq_YMXRqM&OrderID=gRNIBe.l1jQAAAEYoPYMXRqM&ProductID=48tIBe.phvMAAAEWdt1NOLEE&FileName=/jdk-6u4-linux-i586.binWhen I try the above wget command, I get only html files, javascript file, but I don't get the actual .bin download file.
    I got the above download URL from here:
    https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewFilteredProducts-SingleVariationTypeFilter;pgid=m5sy.hOjk2-x8Y;sid=UKAQRO-lOXkQRagRtUZYQQANrvJ_UCLgBULfhfK7tUrq7g==
    I can't get the file through FTP because and FTP download option is not available.
    Any help is appreciated.

    I transferred it over. First i downloaded it on windows and then installed winscp on windows and proftpd on ubuntu and then transferred it from windows to linux.
    I think it would be impossible for anyone using a console browser such as Lynx to download the file, because, html buttons are involved. If it was all just links then it would have been possible.
    But thanks for your reply.
    I wish the make the Java download Lynx (text browser) friendly.

  • Bash shell does not recognise 'java', 'javac' commands (Linux command line)

    i' ve used javac and java compile & execute commands to build the same application on the DOS command line with Windows - no problem.
    But when I try to compile the same file on the command line under Linux Redhat (7.1) using Bash shell i get <bash: javac: command not found> and <bash: java: command not found>.
    In both cases I'm using j2sdk1.4.2 downloaded from java.sun.com for Windows & Linux respectively.
    I make sure I have both the javac and the file I want to compile in the same directory ../j2sdk1.4.2/bin for both the Windows and the Linux applications.
    Is there something I need to do to get bash to recognise javac, java etc? Is there a different setup procedure?
    Any angles on this are much appreciated ..

    Have you tried these correctly..
    Set the CLASSPATH environment variable to include whichever directories you like, eg (on bash) type:
    export CLASSPATH=$CLASSPATH:.:<your java dirs>
    To make java easier to run, put the directory in which it is installed into your path:
    export JAVA_HOME=<where you installed java>
    Then do
    export PATH=$PATH:$JAVA_HOME/bin
    verify it has worked by simply typing
    java
    You can put all of these commands into the .*rc file for your shell, so that they are executed every time you open the shell. So if you are using bash you can put them into ~/.bashrc
    Read up setting the PATH and CLASSPATH for more info.
    This shall resolve the issue .

  • Java API Calls for command line operations

    I would like to use the command line operations programmatically from Java, or PL/SQL.
    I would like to parse a XML file. From DOS Command line I can issue a ifsput test.xml and I can have the file parsed and stored in the database.
    Can I do the same thing programmatically using java or plsql from database.
    Thanks
    Ramna

    The following code allows you to parse an XML file. In this case it parses a string containing a SimpleUserDefinition.
    package ifs.demo.common.users;
    import oracle.ifs.beans.*;
    import oracle.ifs.beans.parsers.Parser;
    import oracle.ifs.beans.parsers.SimpleXmlParser;
    import oracle.ifs.common.*;
    import java.io.File;
    import java.io.StringReader;
    import java.io.FileNotFoundException;
    import ifs.demo.vcard.type.Vcard;
    import ifs.demo.vcard.parser.VcardParser;
    import java.util.Locale;
    import java.util.Hashtable;
    public class UserCreator extends Object {
    private static LibrarySession getConnection(String user,String password,String serviceName, String schemaPassword)
    throws IfsException
    LibraryService service = new LibraryService();
    CleartextCredential me = new CleartextCredential(user,password);
    ConnectOptions connect = new ConnectOptions();
    connect.setLocale(Locale.getDefault());
    connect.setServiceName(serviceName);
    connect.setServicePassword(schemaPassword);
    return service.connect(me,connect);
    private static void createUser(LibrarySession ifs)
    throws IfsException
    String simpleUserString = "<?xml version = '1.0' standalone = 'yes'?>\n"
    + "<SimpleUser>\n"
    + " <UserName>TestUser2</UserName>\n"
    + " <Password>ifs</Password>\n"
    + " <HomeFolderRoot>/home</HomeFolderRoot>\n"
    + "</SimpleUser>\n";
    StringReader userDefinition = new StringReader(simpleUserString);
    SimpleXmlParser xmlParser = new SimpleXmlParser(ifs);
    xmlParser.parse(userDefinition,null,null);
    public static void main(String[] args)
    try {
    LibrarySession ifs = getConnection("system","manager","IfsDefault","manager");
    ifs.setAdministrationMode(true);
    createUser(ifs);
    } catch (IfsException e) {
    IfsException.setVerboseMessage(true);
    e.printStackTrace();
    Note that you ask about doing this from the database. If you mean that you want to run this code from inside the database the answer is not supported in 1.1. What you would need to do is use Oracle Advanced QUeuing to send a message, containing the XML to a process running outside the database and have that process connect to iFS and perform the parsing.
    null

  • How to call linux command ?

    hi all,
    I wanna make java application which display the ouput of linux command (eg. ps -ax output in JTextArea).
    The problem is how to call "ps,kill,etc" ?

    JTextArea txtOutput = new JTextArea();
    String cmd = "ps -a";
    Process proc = Runtime.getRuntime().exec(cmd);
    BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    String out;
    while ((out = buf.readLine()) != null){
    System.out.println("Output: "+out);
    txtOutput.append(out+"\n");
    }

  • How to execute command line by Java

    Hi all,
    I have the following DOS command line that I need to execute it through Java:
    C:\Documents and Settings\Mxmler\Desktop\bin>vr1tovr2 Box.wrl -o Box2.wrl
    I know that I have to use Runtime.getRuntime().exec, But can anyone show me how to use it for the above?
    Thanks

    Mxmler wrote:
    I need your help please
    Forget about the first thread
    vr1tovr2 located inside a sub directory called converted (not in the main directory of the project constructed by eclipse)You have to tell the system where to find the program you're trying to run. You can specify the full path to the executable. Alternatively, you can specify the PATH environment variable when you call exec() (and I presume there's something similar for java.lang.ProcessBuilder). Read the docs.
    Box.wrl & Box2.wrl (will be generated) both of them are located in another directory called usrYou can either specify full paths to those files, or you can set the current working directory when you call exec(). So you'd tell exec() that you're in the directory where those files are. Read the docs.
    I have tried to do the following and I got the following error message: CreateProcess error=2, The system cannot find the file specifiedYou need to do what I said above, in particular, the first one (where you tell the system where to find the program you're trying to run).
    String path = System.getProperty("user.dir");
    String userFolder = "usr";
    String fileName = "mxmler";
    String extension = ".wrl";
    Runtime.getRuntime().exec("vr1tovr2 "
                + Key.QUOTE
                + path
                + Key.FORWARD_SLASH
                + userFolder
                + Key.FORWARD_SLASH
                + fileName + extension
                + Key.QUOTE
                + " -o "
                + Key.QUOTE
                + path
                + Key.FORWARD_SLASH
                + userFolder
                + Key.FORWARD_SLASH
                + fileName + "v2" + extension
                + Key.QUOTE);If you're going to break it down like that, then don't use the version of exec() that takes a single String for the whole command line. Use the version of exec() that takes an array of Strings (the first String in the array is the program to run, and the remaining strings in the array are arguments to that program).

  • Migration (BOXI3.1 - BI4.1) using UMT via Linux command lines

    I have BO4.1 hosted on linux. I am currently doing migration from BOXI3.1 to BI4.1 and need to use linux scripts to call upgrade mgmt tool.
    This is possible only for complete migration.
    However I wanted to know:
    If it is possible to do incremental migration as well using command lines.
    What is the impact on Security Model in case of Complete Migration using command lines. Is it recommended?
    Is it possible to do incremental migration with command lines keeping BIAR file as source?

    Hi,
    Dennis is right. You can install the UMT only on Windows. With this variant you can also use an increment Upgrade even if your Destination BI 4.1 System is on LINUX.
    Doing a Full Stack installation will do the trick. You can also go ahead and install the UMT only but you need additional components (as desribed from Denis). For more info check:
    http://service.sap.com/sap/support/notes/1743789
    And as always, when i read Upgrade Threads, i recommend you follow the Best Pactices for the UMT...makes live easier:
    http://service.sap.com/sap/support/notes/1904814
    Regards
    -Seb.

  • Running a command line in Java

    Dear all,
    I have a question, I need to run a command line in a Java program. The commands line is the next:
    cas.exe -i file1
    I have been seeing in internet and I have tried:
    Process ls_proc = Runtime.getRuntime().exec("cmd /c start D:\\cas>cas.exe -i file1");
    it start the window where the cas folder is... but it dont run the commands line : cass.exe -i file1 :(
    Somebody can help me, please??
    Andrea

    try running it like this.
    Process ls_proc = Runtime.getRuntime().exec("cmd /c start D:\\cas>cas.exe -i file1" +"\n");
    if that does not work put this underneath the original.
    ls_proc.newLine();
    or look into the ProcessBuilder class in java.lang.

  • How to compile forms and reports in linux command line ?

    Hi,
    I'm working on a migration from forms 6i to 11g R2. The development/migration is being made on a Windows 7 64 bits, however, those forms and reports will run on a Linux RHEL 5. Thus, I have to compile them inside that linux box.
    How can I do it? Is there a tool to compile the forms and reports in command line withn a linux box?
    Thanks a lot.

    Thanks for the answer, Carlos.
    I run the command but this error message is displayed "FRM-91500: Unable to start/complete the build".
    Edited by: _blackjack on Dec 18, 2012 5:18 AM                                                                                                                                                                                                                                                                                                                                                                           

  • Compressing a large PDF document using command line or Java code without GUI operations

    hi,
    I have a programatically generated very large PDF file with lots of tables and cells in it. The size of the file is few MBs. Using Adobe pro, I am able to reduce the size of the PDF in KBs. I want to achive it either through a command line or using Java API without GUI interaction.
    I am using JDK1.6.
    Thanks.

    I think you need the scripting or SDK forums http://forums.adobe.com/community/acrobat
    As far as I know, Acrobat does not have command line operation

  • PS3 droplet called from command line in XP reads in files but does not execute action

    Hello.
    I am a researcher interested in anxiety disorders in young children. As part of a functional magnetic resonace brain imaging study we need to compare children's responses to familiar and unfamiliar faces. The latter are no problem, but for the former we need to take pictures of the children's mothers and process them "on the fly" so that they can be incorporated into stimulus sets presented in the MRI machine (otherwise known as the "magnet").
    For presentation in the magnet, the images have to be in a particular format. I have created an action that produces the appropriate format, and a PS3 droplet that behaves appropriately (outputs correctly modified files to the stated address) when a Windows XP (SP3) folder is dropped on it.
    However, I need to automate the procedure further because it will be executed by individuals with little or no understanding of PS etc.
    It occurred to me that I could call my droplet from the XP command line with the folder containing the relevant files as an argument (and then I would be able to incorporate this function into an overall control program).
    However, I have found that this approach loads the relevant files into CS3, but that the actions don't run.
    I would very much appreciate any help with this problem.
    Thank you.
    Adrian Angold.

    A command line script might work, but would lack a user interface. Error
    processing and logging capabilities would also be limited.
    I would consider writing a small application in a language such as Visual
    Basic or C# that uses Photoshop's automation interface. The automation SDK
    is provided on the Photoshop DvD.

  • 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.

  • Command Line Build - Java heap space error

    I'm attempting to build a Flex app via the command line. Even though the build works fine from within the Flash Builder IDE, I get the following error when I attempt to build via the command line
    C:\code\software\web_stuff>"C:\Program Files\Adobe\Adobe Flash Builder Beta 2\FlashBuilderC.exe" --launcher.suppressErrors -noSplash -application org.eclipse.ant.core.antRunner -data "C:\code\software\web_stuff" -file C:\code\software\web_stuff\build.xml WebControlBrowser
    Buildfile: C:\code\software\web_stuff\build.xml
    WebControlBrowser:
    [fb.exportReleaseBuild] Compiling 1 application to C:\code\software\web_stuff\WebControlBrowser\bin-release...
    [fb.exportReleaseBuild] Exception in thread "Code Model Worker" java.lang.OutOfMemoryError: Java heap space
    [fb.exportReleaseBuild]         at org.eclipse.core.internal.runtime.InternalPlatform.getLog(InternalPlatform.java:404)
    [fb.exportReleaseBuild]         at org.eclipse.core.runtime.Plugin.getLog(Plugin.java:282)
    [fb.exportReleaseBuild]         at com.adobe.flexbuilder.codemodel.internal.bridge.WorkspaceSpecification.log(WorkspaceS
    pecification.java:136)
    [fb.exportReleaseBuild]         at com.adobe.flexbuilder.codemodel.internal.parsing.ASTokenizer.parseTokens(ASTokenizer.
    java:386)
    [fb.exportReleaseBuild]         at com.adobe.flexbuilder.codemodel.internal.search.SWCSearchDataProvider.indexFiles(SWCS
    earchDataProvider.java:440)
    [fb.exportReleaseBuild]         at com.adobe.flexbuilder.codemodel.internal.search.SWCSearchDataProvider$2.run(SWCSearch
    DataProvider.java:364)
    [fb.exportReleaseBuild]         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    [fb.exportReleaseBuild]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    [fb.exportReleaseBuild]         at java.lang.Thread.run(Unknown Source)
    BUILD FAILED
    C:\code\software\web_stuff\build.xml:4: java.lang.OutOfMemoryError: Java heap space
    Total time: 1 minute 0 seconds
    FlashBuilderC:
    An error has occurred. See the log file
    C:\code\software\web_stuff\.metadata\.log.
    I've attached the .log file that is referenced.

    Why isn't this documented somewhere? or if it is why isn't it easy to find?
    This link ought to have a link to common issues people run into.
    I just spent an hour trying to solve this same problem. FlashbuilderC.exe wouldn't even work on very small projects until I found this post, so thanks.

  • 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

Maybe you are looking for

  • Using XML to generate 3-d???  Help is needed.

    if anyone can help I will be very grateful. Is it possible to use an xml document to build a graphic, however, I don't mean a graph. for an example if I had an xml doc that specified x,y and z points for a number of (for arguments sake) spheres, I wo

  • 10g - download data

    hi, experts, obi allows users to click the "download data" and save a csv file. however, when I open the exported csv file, the data is not separated by comma it is separated by a space character. is it possible to configure the "download data" funct

  • Create JCO destination option not available

    Dear All, I am trying to make a JCO connection in CE. However the buttons for "Create JCo Destination","Maintain JCo Destinations" are disabled. The status for built-in JCO destinations  WD_MODELDATA_DEST WD_RFC_METADATA_DEST is shown as unknown. The

  • Missing Item Category Group in Sales Area data

    Hi, Can you please help us. We cannot load some materials to our product catalog because of missing item category group in our sales area in crm. Can you please let us know why this happens? I know that this can be fix by doing request load but what

  • HT1920 I forgot the Security Question's Answer and My reset mail doesn't received a confirmation

    I forgot the Security Question's Answer and My reset mail doesn't received a confirmation