Executing one system command from one java class. ERROR. Please help me

Hello i am trying to add users into one linux machine using one jaav program but when i execute the java class the system doesn't show me any error and dont make anything.
The linux command, in the main of the class, is correct; from thelinux shell it runs well, but from the java class it doesn't run.
Can you help me please?
thanks
import java.io.*;
public class ejecutaUsuario {
/** Creates a new instance of ejecutaUsuario */
public ejecutaUsuario(String cmdline) {
try {
String line;
Process p = Runtime.getRuntime().exec(cmdline);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
input.close();
catch (Exception err) {
err.printStackTrace();
System.out.println(err);
public static void main(String argv[]) {
String passwd="hola";
String usuarioInterno="xxxxxx";
new ejecutaUsuario("/bin/sh useradd -p `openssl passwd -1 -salt 12345678 " + passwd + "` -d /home/" + usuarioInterno + " -m -s /bin/bash " + usuarioInterno);

Try gettting the error input stream as well (getErrorStream()). Maybe you are getting output there.
You might want to try just executing the 'useradd' part, getting the output stream of that process, and then put the parameters of useradd into the outputstream.
Later
Cardwell

Similar Messages

  • How to execute a jsp instruction from a java class?

    How to execute a jsp instruction from a java class?
    Any help please.
    Thank's

    I'll detail my problem:
    Supposing that I have a jsp file called: start.jsp
    In the start.jsp I instanciated an object called global from the class Global ( for example ).
    Then, I called a custom taglib:
    <ix:mytag/>
    In the suitable tld file: the mytag is defined:
    <tag>
    <tag class>Tag1<.....
    The java file Tag1 has method:
    doStartTag(){
    // here is the problem
    global.doSomeFunctions();
    Okay, the problem is that the object gobal is not defined in the class Tag1. what to do?
    I think that I have to pass the object global as a parameter to the class Tag1. How to do that?
    Actually, the problem was to insert the follwoing in the doStartTag method:
    doStartTag(){
    pageContext.getOut().print("<%= hello world %>");
    The output is <%= hello world %> not hello world.
    Okay, the new problem is how to pass an object as a parameter to a class called from a tld file.
    Any help please.
    Thank's too much

  • How to: execute operating system commands from PL/SQL

    System: IBM pSeries AIX
    Oracle: 11g Enterprise
    Is there a quick way to execute operating system commands from PL/SQL?
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.

    Is there a quick way to execute operating system commands from PL/SQL?
    NO
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    WHY ON EARTH, such action will create a new connection and become a resource hog?
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Which is perfect for the purpose.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.
    NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
    Sybrand Bakker
    Senior Oracle DBA

  • How to execute Operating System commands from Stored procedure.

    Any help on how to execute Operating System commands from stored procedures will be appreciated.
    Nanditha.

    Search the forums for 'External Procedure' and you will find example code that has been posted before.

  • How can I pass system commands from a java program? Urgent!

    hi,
    I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
    If u have any idea, or have any information about the kind os application reply back.
    Thanks
    Deepa Datar

    This is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
    import java.io.*;
    public class cmddemo2
    public static void main(String arg[])
    try
    System.out.println("cmd");
    Process p=Runtime.getRuntime().exec("cmd.exe");
    DataInputStream din=new DataInputStream(p.getInputStream());
    DataOutputStream dout=new DataOutputStream(p.getOutputStream());
    System.out.println("after streams");
    String s;
    dout.writeChars("type cmddemo2.java");
    while((s=din.readLine())!="\n")
    System.out.println(s);
    dout.writeChars("dir");
    String s1;
    while((s1=din.readLine())!="\n")
    System.out.println(s1);
    System.out.println("over");
    catch(Exception e)
    { System.out.println("Exception : "+e);

  • How to create windows executable file from a java file. Please help.

    Hi,
    For my project I developed the codes in Java. It is working well with java run time environment. But without that I can not run it. I need to create a exe file (windows executable file) from the java source code. If you have any idea please share it with me.
    Even if you know it very lightly, please help with what you know. That would be a big help for me.
    Thank you very much.

    Does anybody know how to read a manual?
    Matt Richardson
    Certified LabVIEW Developer
    MSR Consulting, LLC

  • Need to import my java class. Please help

    Dear all.
    I made a java class named GetOS which contains a method that return th OS name. Then I deployed this class to a Jar file called tarek.jar.
    now I need to import this jar file in my form
    i'm using forms9i release2
    I did the following:
    I copied "tarek.jar" to \\developerhome\forms90\java\
    then I opend the forms builder - program-import java class but my jar file "tarek" doesn't exist in the list.
    please help.

    Dear all
    I solved this problem. I editing the class path of the system control panel>system>advanced and it works fine
    Now i can import my class easly without any problems
    But when the forms builder imported my class , it generates a pl/sql package which contains a function with the same name of the method i did in my class.The problem is I do not know how to call this function
    Function getOSname( obj ora_java.jobject)
    return varchar2 is
    begin
    cls := jni.get

  • " loading failed please check your page for  java script errors" please Help

    recently my project starts crashing.... when it loads it gives a java scrip error .. saying " loading failed please check your page for  java script errors"

    Hey, If you have an error, you should see the error in Edge and you can correct it. In the window/code there will be a red dot too.

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Executing Operstaing System command

    Hi,
    I want to execute an operating system command from my java program. I tried running dir command Runtime classes exec function, but It raised an exception "CreateProcess: dir error=2". I'm using win2k as an operating system.
    Could somebody please help me?
    Thanks
    Manjula

    Hi !
    Using the Runtime class u can execute any exceutable file on the OS like the exe or com on windows. There is no executable file called dir... Instead put the dir command in xxx.bat file and then try executing the batch file.
    I hope this helps...
    Regards,
    Vin

  • Calling another java class from a java class

    Hi Friends,
    I have a class tht works in 2 modes,depending upon which mode i am passing (gui or text) on the command line eg:
    java myclass [mode]
    I want to call this command from another java class,and i wrote this code:
    try
             Process theProcess =
                Runtime.getRuntime().exec("java myclass  "+args[0]);
          catch(IOException e)
             System.err.println("Error on exec() method");
             e.printStackTrace();
          }When i pass "gui" it works fine,but when i pass"text", the class completes and nothing shows up on the command prompt window,so can please somebody tell me how to make this work.
    Thanks

    As aniseed just pointed out, you could do something like this:
    import javax.swing.*;
    class Test extends JFrame {
         public Test(String title) {
              this.setTitle(title);
              this.pack();
              this.setSize(300, 300);
              this.setLocationRelativeTo(null);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) { new Test(argv[0]).setVisible(true); }
    public class Test2 {
         public static void main(String[] argv) {
              Test.main(argv);
    }Run it by executing this command:
    java Test2 "Title of Frame"See if that's not what you're looking for ...

  • Execute Unix Mail Command from Store Procedure

    Hi Colleagues!
    I designed a store procedure that Monitoring some Critical tables in my Oracle 8.0.6.1.0 Database But I need to send some Emails from the Store Procedures to Information System Staff when the amount of rows increase too much. I read about UTL_SMTP but my database version is too old to run this package. Also I have the option of Maildemo8i that execute MS Oulook from a Client System But I looking to Send it from my Database(OS HPUX). So please take a look of this issue and I will appreciate any help.
    Your Friend.
    Emmanuel Carrillo Trejos.
    LNB, Republic of Panama(Central America).
    P.D. You can email to: [email protected]

    Do you mean that you want to execute mail or mailx unix commands to send mails.If i am right then probably you are looking for a way to execute operating system commands from your procedure.
    You can refer this link if you want to do that. You need java support in your Oracle database and i believe that Oracle 8 does have jvm running in the instance.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:5079825575573830264::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241
    Thank you!

  • How to execute system command from java program

    Hi all,
    I want to change directory path and then execute bash and other unix commands from a java program. When I execute them separately, it's working. Even in different try-catch block it's working but when I try to incorporate both of them in same try-catch block, I am not able to execute the commands. The change directory command works but it won't show me the effects of the bash and other commands.
    Suggestions??

    The code I am using is....
    try
    String str="cd D:\\Test";
    Process p=Runtime.getRuntime().exec("cmd /c cd
    "+str);your str string is already having cd in it but again you ar giving cd as part of this command also please check this,i will suggest you to remove cd from str
    Process p1=Runtime.getRuntime().exec("cmd /c mkdir
    "+str+"\\test_folder");you should say mkdir once you change your path,but here you are saying mkdir first and then cd D:\Test(this is because of str)..please check this
    Process p2=Runtime.getRuntime().exec("cmd /c bash");
    Process p3=Runtime.getRuntime().exec("cmd /c echo
    himanshu>name.txt");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    Message was edited by:
    ragas

  • Calling Operating System Commands from PL/SQL using java

    Calling Operating System Commands from PL/SQL - The Java Way
    wlth help of given thread link,
    Calling OS Commands from Plsql
    but i had user privilege problem
    Declare
    x Varchar2(2000);
    Begin
    x := OSCommand_Run('/tmp/sri/GROUP_ho.sh');
    DBMS_OUTPUT.Put_Line(x);
    End;
    o/p;
    can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
    i done the grant privillage also
    part
    dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    dbms_java.grant_permission('
    abcd', 'SYS:java.io.FilePermission','<<ALL FILES>>', 'execute');
    again
    get
    can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
    same error;

    Process management at the OS level should prevent execution continuing in the calling code until the command has completed (either successfully or with error).
    If the low level java code were to spawn child process threads then execution could continue, but I'm guessing the Java function your talking about doesn't do that and just calls the operating system to execute the command and waits for the returning code to come back.

  • Executing a bash command from Java

    I want to execute a bash command from within a Java application on the server. I know how to do simple commands, but this command is killing me. I get nothing back when I send it.
    p = Runtime.getRuntime().exec(new String[]{"ps","-ef","","grep","evolution"});
    There is also another part where I want the results piped to awk and fetch out the pids. BUt with this not working the rest is a waste for now.
    Robbie

    evgeni00 wrote:
    Thank you for assuming the posters' stupidity.I can only see the information that you provide. You didn't say you tried the recommendations.
    I read the article and I tried the things he/she is proposing, also the error stream, guess what it outputs: nothing.Maybe you did it wrong. If you didn't do it wrong, then that program you're invoking is poorly written, because it dies in error without producing any error messages.
    And I also searched for the exitValue 138, but didn't get much further than that its some system specific value. If you know where I can find more information, I would appreciate if you let me know about it. As jschell pointed out it's probably app specific. You can search the source code and/or documentation of that program to see if they say what 138 means.
    Apart from that -- it seems that environment and run directory issues can trip this up. Try checking that stuff out. Maybe your program expects something on the executable PATH that isn't there. Or maybe you're not running it in the working directory that you think you are.

Maybe you are looking for