Solved

Running a unix script from a java program

Posted on 2008-10-01
5
505 Views
Last Modified: 2013-12-26
I writing a program which has to execute a shell script but it cant. But I can  execute other commands like mv without a problem. here is my code snipet. "
try
            {
                String s = null;
                String [] cmd = new String [];
                cmd [0] = "sh";
                cmd [1] = "-c";
                cmd [2] = "mv eppix/calls/nml/unproctest/" + myFiles [i] + " u1/LOADED";
                cmd [3] = "./TT_TEST_load.sh eppixgui";
                             
                Process process = Runtime.getRuntime ().exec (cmd);
   
            }
            catch (Exception e)
            {
                e.printStackTrace ();
            }

the mv commnad excutes without a problem but ""./TT_TEST_load.sh eppixgui";: this script doest wnat to run. But when I run the script directly on the shell it runs without problems please help
try
            {
                String s = null;
                String [] cmd = new String [];
                cmd [0] = "sh";
                cmd [1] = "-c";
                cmd [2] = "mv eppix/calls/nml/unproctest/" + myFiles [i] + " u1/LOADED";
                cmd [3] = "./TT_TEST_load.sh eppixgui";
                              
                Process process = Runtime.getRuntime ().exec (cmd);
    
            }
            catch (Exception e)
            {
                e.printStackTrace ();
            }

Open in new window

0
Comment
Question by:mafifi
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22616312
I may be mistaken but ./ signifies current folder, so ensure that you are executing this with the that .sh in the same folder as your java program.

If not, you will have to change directories OR use absolute path.
0
 

Author Comment

by:mafifi
ID: 22616340
The Java program in in the same folder as the script.
0
 
LVL 12

Expert Comment

by:basav_com
ID: 22619972
Similar type of question has been answered here.
http://www.experts-exchange.com/Programming/Languages/Java/New_to_Java/Q_23743912.html
Can you pls check the current directory by running 'pwd' command as said by Venabili / mwvisa1.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 22620821
May I ask,
why are you running the shell script to move files around? Java has method File.renameTo that moves files or folders.
0
 
LVL 9

Accepted Solution

by:
mbodewes earned 500 total points
ID: 22626723
So if you write this out you get:

"sh" "-c" "mv eppix/calls/nml/unproctest/" + myFiles [i] + " u1/LOADED" "./TT_TEST_load.sh eppixgui"

Which is a bit weird because it will see both "eppix/calls/nml/unproctest/" + myFiles [i] + " u1/LOADED" but also "./TT_TEST_load.sh" and "eppixgui" as arguments to the mv command. Isn't it possible to create a shell script that takes one argument (myFiles[i]) and executes everything you try to put in the cmd[] array?

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 60
Problem to App 4 99
Facing this issue for maven proxy setting 2 21
pagenation logic how it is working in my code 1 58
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question