Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

java Runtime

Posted on 2003-03-26
3
Medium Priority
?
317 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
  • 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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

564 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