?
Solved

java Runtime

Posted on 2003-03-26
3
Medium Priority
?
315 Views
Last Modified: 2012-05-04
I am using a Verio FreeBSD server that offers some tools for user management. They provide a command, vadduser, that allows you to add a user with extensions to avoid prompting. I tested it at the command prompt and it worked fine. However, when I run the command from a java Runtime process, it mistakes a quotation for a character. I think it might have to do with the \" I use in my string, but I'm not sure.

---------------------------------------------------------------
Here is a piece of my code:
----------------------------------------------------------------
String command = "vadduser --login=jack --password=black --fullname=\"Jack Black\" --home=/usr/home/markfabr/jblack --services=\"ftp,0;mail,2\"";

Process ls_proc = Runtime.getRuntime().exec(command);

// get its output (your input) stream
           
BufferedReader ls_in = new BufferedReader(new InputStreamReader(ls_proc.getInputStream()));
BufferedReader ls_er = new BufferedReader(new InputStreamReader(ls_proc.getErrorStream()));
       
try {
     while ((ls_str = ls_in.readLine()) != null) {
          out.println(ls_str);
     }
     while ((ls_str = ls_er.readLine()) != null) {
          out.println(ls_str);
     }
     ls_proc.getErrorStream().close();
      ls_proc.getInputStream().close();
      ls_proc.getOutputStream().close();
               
} catch (IOException e) {}

---------------------------------------------------------------------
And here is the output to the browser:
---------------------------------------------------------------------
Argument "2"" isn't numeric in addition (+) at /usr/local/lib/perl5/site_perl/5.6.1/VPS/Privs.pm line 279.

---------------------------------------------------------------------
Also, The value that is added to the database for fullname is "Jack.


Any help would be greatly appreciated.

Thanks,

Mark Fabrizio
0
Comment
Question by:aintry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 8213785
This looks more like a problem in the perl mod.

Here is a test I ran.

I created a class like yours and created a vadduser.bat that would just echo back the command line args. Both files are below.

import java .io.*;

public class RunTimeTest{
     public static void main(String[] args) throws Exception{
          String command = "vadduser.bat --login=jack --password=black --fullname=\"Jack Black\" --home=/usr/home/markfabr/jblack --services=\"ftp,0;mail,2\"";
          Process ls_proc = Runtime.getRuntime().exec(command);

          BufferedReader ls_in = new BufferedReader(new InputStreamReader(ls_proc.getInputStream()));
          BufferedReader ls_er = new BufferedReader(new InputStreamReader(ls_proc.getErrorStream()));

          String ls_str;

         while ((ls_str = ls_in.readLine()) != null) {
               System.out.println(ls_str);
          }
         while ((ls_str = ls_er.readLine()) != null) {
               System.out.println(ls_str);
          }
          ls_proc.getErrorStream().close();
          ls_proc.getInputStream().close();
          ls_proc.getOutputStream().close();
     }
}


//--********vadduser.bat*******--//

@echo off
:getArgs
if %1a==a goto end
@echo %1
shift
goto getArgs

:end
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 225 total points
ID: 8213793
This was the output :

--login
jack
--password
black
--fullname
"Jack Black"
--home
/usr/home/markfabr/jblack
--services
"ftp,0;mail,2"


So you can see that the command is being executed as designed.
0
 

Author Comment

by:aintry
ID: 8213933
Thanks for your quick responce ozymanis.

I figured that it wasn't the java itself because when I printed out the String it was exactly as it should be. I'll try looking in to vadduser perl script and see what I can make of it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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