Running Shell script from command line

Hi,
I am getting a Exception in thread "main" java.lang.NoClassDefFoundError: TestRuntime/java error when I run the following code on my linnux box...can anyone please help
import java.io.*;
public class TestRuntime {
        public static void main(String args[]) {
                Runtime runtime = Runtime.getRuntime(); //get runtime information
        try {
                        Process Child = runtime.exec("/usr/bin/ksh"); // execute command
                        BufferedWriter outCommand = new BufferedWriter(new OutputStreamWriter(Child.getOutputStream()));
                        outCommand.write("/home/mypath/tesh.csh");
                        outCommand.flush();
                        try {
                                Child.waitFor(); // wait for command to complete
                        } catch (InterruptedException e) { // handle waitFor failure
                                System.out.println("ERROR: waitFor failure");
                                System.exit(10); // exit application with exit code 10
                } catch (IOException e) { // handle exec failure
                        System.out.println("ERROR: exec failure" + e);
                        System.exit(11); // exit application with exit code 11
}

If I'm reading your code correctly, you're starting a Korn shell session, then executing your C shell script as if you were at at the session window's prompt. If that is correct, you haven't caused your standard out (stdout) to hit ENTER yet. I'm not an expert, but I hope this works for you.
Your code:
Process Child = runtime.exec("/usr/bin/ksh"); // execute command
                        BufferedWriter outCommand = new BufferedWriter(new OutputStreamWriter(Child.getOutputStream()));
                        outCommand.write("/home/mypath/tesh.csh");
                        outCommand.flush();I think you need to enter one extra line before the flush():
Process Child = runtime.exec("/usr/bin/ksh"); // execute command
                        BufferedWriter outCommand = new BufferedWriter(new OutputStreamWriter(Child.getOutputStream()));
                        outCommand.write("/home/mypath/tesh.csh");
                        outCommand.newLine();  // hit ENTER
                        outCommand.flush();P.S. If you're running this script and your Java program from the same UNIX machine, you could just execute the shell script inside the runtime.exec() call.

Similar Messages

  • Running Oracle Scripts from Command Line

    Hi,
    How can i run Oracle scripts from command line.
    Actually i need to run these scripts from MSBuild before running Unit test projects

    C:\>sqlplus @myscript
    That would be the easiest variation
    C:\>sqlplus user/passwd@tns_alias @myscript
    would be an often used variation
    And then there is of course the version with parameter passing:
    C:\>sqlplus user/passwd@tns_alias @myscript param1 ... paramx
    Dunno about MSBuild

  • How to run Endeca Graphs from command Line

    Hi,
    I would like to know if there is any way to run Endeca Graphs from command line in Windows.
    Thank you,

    The correct way to execute a graph using the command line in windows is.......
    Execute the following command from the project folder:
    C:\Oracle\Endeca\Discovery\3.1.0\IntegratorETL\configuration\org.eclipse.osgi\bundles\5\1\.cp\lib\bin\clover.bat -plugins "/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/5/1/.cp/lib/plugins;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/6/1/.cp/lib/plugins/;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/9/1/.cp/lib/plugins/;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/14/1/.cp/lib/plugins/;C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/21/1/.cp/lib/plugins/;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/23/1/.cp/lib/plugins/;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/plugins/com.endeca.latitude_1.0.0/lib/plugins/;/C:/Oracle/Endeca/Discovery/3.1.0/IntegratorETL/configuration/org.eclipse.osgi/bundles/358/1/.cp/lib/plugins/" -noJMX graph\graph_name.grf
    Our costumer needed to run some ETL process from ODI and once it finished start a Clover ETL process (automatically). So we created a .bat file witth the above command and then in ODI we created a package with all ETL interfaces and the last step of the package was a OScommand component that excecuted the .bat script from the Endeca's project folder.
    Hope you find this post helpfully.

  • To run a report from command line, when using jdbc-odbc bridge

    Hi,
    How to run a report from command line, when using jdbc-odbc bridge?
    Usually with tns, we do by "rwrun module=<> userid=<user>/<passwd>@tns".
    with odbc, we do by "rwrun module=<> userid=<user>/<passwd>@odbc:DSN"
    Please specify, what is command line arguments for jdbc-odbc bridge driver?
    Environment : Oracle 9i Report Builder on WinNT
    Database : Sybase
    Regards,
    Ramanan

    Hello Ramanan,
    Report Builder : connect JDBC Query in Report Builder is to through Connection Dialog in JDBC Query Editor. User can use a Sign on parameter (can use, default : P_JDBCPDS or can create new) to connect to JDBC Data Source. Connection once made will be mentioned and will be reused through out Reports Builder.
    JDBC PDS allows user to connect one or more same or different kind of databases.
    While running report through runtime or Server, user can pass the sign on parameter(connection string) value, like any other user parameter.
    Syntax for connection string : <username>/<password>@databaseURL . The syntax of database part of connection string depend on the type of JDBC Driver used to connect to Data Source while designing the JDBC Query. databaseURL refer to the location of the database and its format depend on the JDBCPDS river selected in design time while creating the JDBC Query.
    rwrun eg :
    rwrun report=jdbc_odbc.rdf destype=file desname=output.html desformat=html P_JDBCPDS=scott/tiger@database
    Server eg :
    http://server.com:8888/servlet/RWServlet?server=MyReportServer+report=jdbc_odbc.rdf+destype=cache+desformat=html+P_JDBCPDS=scott/tiger@database
    http :
    Please see ORACLE_HOME/reports/conf/jdbcpds.conf for more information.
    With Regards
    Reports Team

  • How to run an executable from command-line

    I'm learning how to use the Terminal and I got stuck in a silly thing (I suppose it is). How can I run an executable file from command-line in Terminal?
    For example: I have a file named "Hello" in the folder /sample. If I use the ls command (ls sample), I can see the file Hello. Then I move to the directory (cd /sample) and try to run the file Hello (typing "Hello") but I got "command not found" message.
    If I drag the Hello file from Finder to Terminal and hit Return, it runs perfectly. And if I type the full path to the file (even if I'm already inside its directory), it also runs.
    So, my doubt is if there is any command to run an executable from command-line.
    Thanks

    KJK555 wrote:
    Hi VK:
    Can you enlighten me on why it's neccessary to do the "./" thingy in OS X when in unix/linux
    I never had to resort to doing that?
    Kj
    I took the trouble of reading *man bash* and it explains the issue. to add the current directory to PATH you need to add an empty path to PATH like this
    PATH=$PATH::
    you can add it to ~/.bash_profile so that it's executed automatically when you start bash. I suspect the linux system you are talking about had this set up by default or had it added to PATH in /etc/profile which defines PATH globally.

  • Run test case from command line

    Hi  All,
    Working environment : VS 2013 professional 
    Project type : Unit test project for (Windows 8.1 and Windows phone 8.1)
    I have a set of unit test cases and want to run it on command line.I tried MSTest.ext and vstest.console.exe for running test case but not succeed.  
    command :  MSTest.exe /testcontainer:path of project dll
    command :  vstest.console.exe path of project dll
    Type of Error
    Error : Unit test case for windows store and windows phone app can't be run outside appcontainer. 
    Error : No tests to execute
    command :  MSTest.exe /testcontainer:path of appx
    command :  vstest.console.exe path of appx
    Error : root certificate error 
    I just want to run windows 8.1 and windows phone 8.1 run test cases from command line.
    Thanks in advance.

    Hi vicky2468,
    Based on your issue, as far as I know that if we want to run unit test for windows store and windows phone app using mstest.exe or vstest.console.exe in command line, you will need to execute the .appx instead of the dll in command line.
    In addition, I tried to run the appx for unit test in command line,
    but I found that I also get the same issue as yours. I could not execute the appx for unit test in command line successfully.  But if we run it with VS IDE in Test
    Explorer windows, it seems that it works fine.
    So I suggest you can submit a feedback for this issue, to get the issue confirmed and diagnose by product team, would you please create connect report for it? You will get email notification for update.
    http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx
    When you submit the connect, I suggest you can provide your project for product team so that product team will
    be better help you solve this issue.
    If you submit it, please share me the link here, I will help you vote it. I think we could get the latest information
    from the product team experts. Of course, if I get any latest useful information, I will update it here.
    Thanks for your understanding.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Running SQLPLUS script from command prompt on SUN

    We are making a migration from VMS to SUN ( SunOS 5.10) and from 9i to 10g. We have encountered an unanticipated problem with running scripts from the command line in SUN(SQLPLUS execution from the command line). All of our packages have a naming convention such as "DM$LOAD.PKB". I know it is a strange naming convention.
    The problem is that when the package creation script is run in SQLPLUS at the command prompt SQLPLUS can not open the file.
    SQL> @dm$load.pb
    SP2-0310: unable to open file "dm$load.pb"
    SQL> host ls
    dm$load.pkb
    SQL>
    Setting the escape character does not seem to help.
    SQL> set escape '\'
    SQL>
    SQL> @dm\$load.pb
    SP2-0310: unable to open file "dm$load.pb"
    SQL>
    Unfortunately, we can not rename the scripts. This can be done from a shell script, but our Tech Services refuse to run the SQL scripts from a shell script
    Any ideas on how to get SQLPLUS to run the scripts from the SUN command line?

    I did not notice that the cut and paste was poor. It should have read
    SQL> @dm$load.pkb
    SP2-0310: unable to open file "dm$load.pkb"
    SQL> host ls
    dm$load.pkb
    Any ideas will be greatly appreciated.

  • Run shell script from plsql

    You can use utl_tcp to do http posting, send email, and ftp files. Has anyone ever executed a unix shell script from plsql on a remote unix box?

    I am actually asking about running a script file on a remote machine, not on the host. A java procedure or c file extproc call could be used to call a host script file.
    A key limitation of this java procedure method is shown in the ask tom reference:
    if you can do it from sever A on the command line (outside of oracle), we can do
    it inside the database.
    Solve that problem and we'll go from there. Oracle cannot bypass the OS and do
    magical things beyond what you've set up at the OS level.
    since utl.tcp opens a tcp connection, can you open a telnet session using utl_tcp and low level command formatting? I didnt have much trouble creating a plsql based ftp client, has anyone seen a plsql based telnet client?

  • Running FlexUnit tests from command line

    Sorry if that has been posted before: I searched best I could and nothing came up.
    I am interested in building and running my unit tests from the command line so we can add it to a nightly build process.
    I am *very* new to all this: basically I picked up Adobe Flash Builder 4 a month ago and I have done *everything* inside that IDE: writing code, building, testing, running.
    I looked into at least how to build something from the command line, I found this:
    http://help.adobe.com/en_US/flashbuilder/using/WSbde04e3d3e6474c4-59108b2e1215eb9d5e4-8000 .html
    Can't get past this error:
    Buildfile: /Users/dbanks/build_test.xml
    BUILD FAILED
    Target "FlexUnitApplication" does not exist in the project "null".
    Total time: 0 seconds
    Adobe Flash Builder 4:
    An error has occurred. See the log file
    /Users/dbanks/Documents/Adobe Flash Builder 4/.metadata/.log.
    Plus, even if I got this going, I am just building the swf.  I also want to run it and capture the output in some meaningful way that can be read/evaluated/acted on.
    FWIW, the script/xml I am using to try to build:
    build_test.xml:
    <?xml version="1.0"?>
    <project default="main">
        <target name="main">
            <fb.exportReleaseBuild project="NightclubMogul" />
        </target>
    </project>
    execute_build_test.sh:
    WORKSPACE="$HOME/Documents/AdobeFlashBuilder4"
    # works with either FlashBuilder.app or Eclipse.app
    "/Applications/AdobeFlashBuilder4" \
        --launcher.suppressErrors   \
        -noSplash   \
        -application org.eclipse.ant.core.antRunner   \
        -data "$WORKSPACE"    \
        -file "/Users/dbanks/build_test.xml" FlexUnitApplication
    I am not clear what in here is actually supposed to point to where my project lives: it's off in some directory somewhere.  I see that I am pointing to a workspace (Documents/AdobeFlashBuilder4) but when I poke around in there I don't see anything connecting back to the directories where the code lives.
    Any help would be great: getting the tests to build from command line, then getting them to run.

    C:\>sqlplus @myscript
    That would be the easiest variation
    C:\>sqlplus user/passwd@tns_alias @myscript
    would be an often used variation
    And then there is of course the version with parameter passing:
    C:\>sqlplus user/passwd@tns_alias @myscript param1 ... paramx
    Dunno about MSBuild

  • Running shell scripts from GUI

    I'm trying to run a simple shell script (bash or sh) from the GUI (just double click it).
    I've managed to run it by double clicking, BUT, it runs from my home directory (even if i add --noprofile or remove #!/bin/bash line completely).
    How can I keep the current directory, or at least get it as a variable?
    Thanks,

    Hi
    If you are using the Oracle database 10g, the new dbms_scheduler package allows you to run shell scripts. The dbms_scheduler.create_job procedure have one parameter called the job_action in which you specify the full path of the shell script.
    I hope this will help

  • Running shell scripts from within oracle. A big task is forgotten

    Dear List,
    I have some shell shell scripts which do some tasks on the linux OS level.
    I am calling the Korn scripts using a java class, which in turn is being called from a PLSQL function.
    All but one of the 10 script works fine. This is the script which does the most work, and takes on average 40 minutes usually.
    Why does Oracle forget the running of the shell script? I wait in my PLSQL function for the return code, but it never comes. The scripts I have not written myself !
    I look forward to your reply on this matter.
    regards
    Ben

    Hi
    If you are using the Oracle database 10g, the new dbms_scheduler package allows you to run shell scripts. The dbms_scheduler.create_job procedure have one parameter called the job_action in which you specify the full path of the shell script.
    I hope this will help

  • Running Shell Script from

    Dear Friends!
             I have one requirement, I have to trigger Unix Shell script from ABAP program.   but only twist in the story is my SAP box is not in Unix system so I cant use external command execute function module.  Is any one come accross to such scenario ? Please advice on this that How we can do this task.
    I have one idea like
    I can make shell script from ABAP put into FTP directory of Unix using webservice and schedule the background job or something in UNIX so after some time it get executed but not sure on this. if we can achieve this in real time it will be really cool compare to background job or something.
    Please give me your expert advices. Any help from you will be greatly appreciated.
    Thanking you and Regards
    Naeem

    I use PI for this.

  • [solved]can't run java apps from command line

    Every Java program that i've tried to run from command line gives me a error message like this:
    augusto java% java Test
    Exception in thread "main" java.lang.NoClassDefFoundError: Test
    Caused by: java.lang.ClassNotFoundException: Test
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Test. Program will exit.
    `java Test.class` doesn't work too.
    but, the exact same code work from eclipse, am I missing something?
    Some info:
    % ls Test*
    Test.class Test.java Test.java~
    % cat Test.java
    public class Test{
    public static void main(String[] args){
    System.out.println("doesn't work");
    % echo $PATH
    /home/augusto/.bin:/home/augusto/.bin:/home/augusto/GNUstep/Tools:/opt/GNUstep/Local/Tools:/opt/GNUstep/System/Tools:/bin:/usr/bin:/sbin:/usr/sbin:/opt/java/bin:/opt/java/jre/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin
    Last edited by hack.augusto (2009-10-27 00:57:53)

    also make sure that you current directory is in your classpath.
    eg
    export CLASSPATH=".:$CLASSPATH"
    java Test
    your issue is more likely to be classpath related, as java doesn't read the path variable, and the java executable is found
    Last edited by bruce (2009-10-27 01:02:51)

  • Running Unit Test from test manager that run bat file from command line

    Hi ,
    I am trying to run Jsystem (java framewotk) from command line using runScenario.bat thru unit test that i associated to test in test manager.
    the idea is that when i ran the automated test  from MTM - it will run the the unit test that will run the appropriate test case in java.
    i wrote the code like this : 
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    namespace UnitTestProject3
    [TestClass]
    public class UnitTest1
    [TestMethod]
    public void TestMethod1()
    try
    String command = "c:\\JSYSTEM\\runner\\runScenario.bat
    c:\\Users\\ryeshua\\Source\\Workspaces\\Auto1\\my-tests-project\\target\\classes scenarios\\feature1 RoeySetup.xml ";
    System.Diagnostics.ProcessStartInfo procStartInfo =
    new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
    procStartInfo.RedirectStandardOutput = true;
    procStartInfo.UseShellExecute = false;
    //procStartInfo.CreateNoWindow = true;
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    proc.Start();
    string result = proc.StandardOutput.ReadToEnd();
    Console.WriteLine(result);
    catch (Exception objException)
    // Log the exception
    and when i ran it from visual studio it worked perfect. and update  the Jsystem logs of the junit test in the jsystem/runner/log folder.
    but when i added it to associated test and ran it from MTM - it pass but it does not update  the logs in jsystem folder.
    the problem that i dont know what is not working. i cant see the output of it when i ran from mtm but can see when i ran from VS.
    i am using VS 2013 Pro with MTM 2013.
    please advice
    Roey

    Hi Roey,
    Thank you for posting in MSDN forum.
    Based on your issue, could you please tell me how you generate the log file under the jsystem folder?
    Generally, I know that when we run unit test from VS IDE, the file will be saved into the local machine. But when we run unit test from MTM, the unit test method will be run on the test agent machine, so the file will be saved into the test agent machine.
    Therefore, I suggest you could check if you did not see the updated logs file in jsystem folder on the test agent machine.
    In addition, I suggest you could try to copy this unit test project on this test agent machine and then run the unit test method using mstest.exe in command line and then check if you can update the logs file.
    https://msdn.microsoft.com/en-us/library/ms182489.aspx?f=255&MSPPError=-2147217396
    If you have any updated message about this issue, please tell me.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Run Shell script from oracle plsql

    OS--> Linux
    Version--Oracle 10g
    I want to run a shell script from oracle PL/sql. I know dbms_scheduler can be used to create job , enable job and run it .
    But I have a requirement where I need to know if my script ran successfully or not. Something like a return code back to oracle.
    So that I can run appropriate code depending on return code of executed Script.
    Kindly help !!

    Online documentation was invented for a reason.
    And this reason was not would look it, as a volunteer, on your behalf, and post it in this forum.
    All procedures are documented. There are examples for most facitlities on Asktom, and there is Morgan's Library at [http://www.psoug.org]
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • !How to find out follow up activities created during creation of an Order??

    Hi Gurus, I want to find out the number of follow up activities created during creation of an Order?? Is there any BAPI or Function Module which can detrmine the number of follow up activities after creation / saving an Order.. Please Reply fast. Tha

  • F4 help not showing for currency translation types

    Friends, I have a scenario where I need to convert currencies in my query based of different tranlastion types. I maintained a variable in RRC1 and it's working fine when I execute the query. It asks for the variable - shows different available optio

  • Mail and Previews

    Whenever I receive an email with an attachment the attachment does not show the accurate preview. For example when I receive a pdf fax every fax following shows the same preview when I scroll down the various emails. Entourage doesn't do this? What g

  • API call to get FULL URL

    I can't seem to find an API call to simply return the full url of the current page. I just want to do the simplest (at least I think it should be simple) thing: Call a stored procedure (from a portlet) passing the current full url to the procedure. N

  • Query server name where a BLS tran is executed ?

    Hi all, is there a possibility to query the server name where a BLS transaction is executed from within the transaction? Use: The transaction should be able to decide if called on a test server or in production. I am looking for a logic that lets the