axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From artifex <e65...@bsnow.net>
Subject Re: Problem with Runtime.getRuntime() exec
Date Thu, 18 Jun 2009 22:22:29 GMT

Thank you, Andreas
I've checked environ:
sudo netstat -anp | grep 8080  // got PID by this comand
sudo cat /proc/<PID>/environ 
The ouput is the same as I received by the webservice (...that snippet,
which prints all env variables). So it's just another way to check(not to
add or edit) what env variables are avaliable in runtime for your
webservice, but the problem isn't solved...still the same question:

***********How to set up your own environment variable, which you would like
to use(var=System.getenv(ENV_VARIABLE);) inside some class of your web
service ?******************************* 

Thanks for help
 

Andreas Veithen-2 wrote:
> 
> If System.getenv returns null, then this means that the environment
> variable is not set on the process. This has nothing to do with class
> loaders or the fact that you look up the variable from within a
> service. You can check that by looking at /proc/<pid>/environ, where
> <pid> is Tomcat's process ID.
> 
> Andreas
> 
> On Thu, Jun 18, 2009 at 18:38, artifex<e65447@bsnow.net> wrote:
>>
>> Things in use:
>> Ubuntu 9.04 (jaunty)
>> Tomcat 6 (deb package)
>> Axis2
>> Maven
>> Eclipse
>> other
>> ....
>>
>> There is some other information:
>> System.getenv("ENV_VARIABLE") will return null in this case, because the
>> variable doesn't exist.
>> if we run this snippet inside some class, which is part of our web
>> service:
>>
>> Map map = System.getenv();
>> Set keys = map.keySet();
>> Iterator iterator = keys.iterator();
>> while (iterator.hasNext()) {
>> String key = (String) iterator.next();
>> String value = (String) map.get(key);
>> System.out.println(key + " = " + value);
>>
>> --- we will get a list of environment variables and this list is
>> different
>> from that you get in command line : env
>> (I'm using Ubuntu)
>>
>> Even if I set up my own env variable under root(for example like this:
>>
>> sudo gedit /etc/environment
>> ENV_VARIABLE=/home/user/some_folder //put this line in /etc/environment
>> and
>> save then reboot
>> ) --- then rebuild and redeploy service(just in case) which contains
>> class
>> with above snippet,  I cannot see ENV_VARIABLE in output of tomcat
>> console
>> (catalina.sh run)
>>
>> So now the question is :
>>
>> ***********How to set up your own environment variable, which you would
>> like
>> to use(var=System.getenv(ENV_VARIABLE);) inside some class of your web
>> service ?*******************************
>>
>>
>> Deepal Jayasinghe wrote:
>>>
>>> Hmm, I am not so sure that has something to do with the class loader, if
>>> that is the case then problem might be due to each service has its own
>>> class loader and it is different from context class loader. Anyway as I
>>> remember correct no one asked this kind of question before, so if you
>>> find that answer please post that too.
>>>
>>> Thanks,
>>> Deepal
>>>
>>> artifex wrote:
>>>> That thing didn't work because it couldn't find path to the  desired
>>>> program
>>>> for execution.
>>>> I'm using environment variables in my java code("String envV =
>>>> System.getenv("ENV_VARIABLE");"), but it seems that   getenv() cannot
>>>> find
>>>> the variable. I'm sure it's set up correctly. So now my goal is to find
>>>> out
>>>> how we can get environmental variables if classes which try to get it
>>>> are
>>>> inside a web service(???)...
>>>>
>>>> ...if anyone knows please give me a hint...
>>>>
>>>>
>>>> artifex wrote:
>>>>
>>>>> I have deployed a webservice using Axis2. It works fine, but ....
>>>>> Here is a problem: I need to run an external program through the
>>>>> Client,
>>>>> so I've put in existing library piece of code, which contains
>>>>> Runtime.getRuntime(). When I run test, it works fine, but no external
>>>>> program is run. It seems like piece of code with  "Runtime rt =
>>>>> Runtime.getRuntime();"(it works when is run locally) just ignored...
>>>>> Could anyone help me with this issue?
>>>>>
>>>>> This is class to be wrapped :
>>>>> package eu.project.samplewebservice;
>>>>>
>>>>>
>>>>>
>>>>> import java.io.BufferedReader;
>>>>>
>>>>> import java.io.InputStream;
>>>>>
>>>>> import java.io.InputStreamReader;
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> public class SampleExistingLibrary {
>>>>>
>>>>>
>>>>>
>>>>>     /**
>>>>>
>>>>>      * Adds two input integer parameters and returns the result.
>>>>>
>>>>>      *
>>>>>
>>>>>      * @param i1
>>>>>
>>>>>      *            An integer input
>>>>>
>>>>>      * @param i2
>>>>>
>>>>>      *            An integer input
>>>>>
>>>>>      * @return The integer result which is the sum of the two input
>>>>> integers
>>>>>
>>>>>      */
>>>>>
>>>>>     public int addTwoIntegers( int i1, int i2 ) {
>>>>>
>>>>>             System.out.println( "TEST!!!!!!" );
>>>>>
>>>>>         ///!!!!!!!!!!!
>>>>>
>>>>>                     String mkcolpath = System.getenv("MKCOLPATH");
>>>>>
>>>>>                     String pafpath = System.getenv("PAFPATH");
>>>>>
>>>>>                     //System.out.print(mkcolpath);
>>>>>
>>>>>                     try
>>>>>
>>>>>                 {
>>>>>
>>>>>                     Runtime rt = Runtime.getRuntime();
>>>>>
>>>>>                     Process proc = rt.exec("supertux");
>>>>>  //this is a game
>>>>>                     //pathToCollectionF = pafpath+"/collection.mf";
>>>>>
>>>>>                     InputStream noerr = proc.getInputStream();
>>>>>
>>>>>                     InputStream stderr = proc.getErrorStream();
>>>>>
>>>>>                     InputStreamReader isr = new
>>>>> InputStreamReader(stderr);
>>>>>
>>>>>                     BufferedReader br = new BufferedReader(isr);
>>>>>
>>>>>                     InputStreamReader isr1 = new
>>>>> InputStreamReader(noerr);
>>>>>
>>>>>                     BufferedReader br1 = new BufferedReader(isr1);
>>>>>
>>>>>                     String line = null;
>>>>>
>>>>>                     //System.out.println("<OUTPUT>");
>>>>>
>>>>>                     while ( (line = br1.readLine()) != null
|| (line =
>>>>> br.readLine()) != null){
>>>>>
>>>>>                             System.out.println(line);
>>>>>
>>>>>                     }
>>>>>
>>>>>                     //System.out.println(line);
>>>>>
>>>>>                     //System.out.println("</OUTPUT>");
>>>>>
>>>>>                     int exitVal = proc.waitFor();
>>>>>
>>>>>                     //exitValCl=exitVal;
>>>>>
>>>>>                     System.out.println("Process exitValue:
" +
>>>>> exitVal);
>>>>>
>>>>>                 } catch (Throwable t)
>>>>>
>>>>>                   {
>>>>>
>>>>>                     t.printStackTrace();
>>>>>
>>>>>                   }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>             ///!!!!!!!!!!!
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>             return i1 + i2;
>>>>>
>>>>>
>>>>>
>>>>>     }
>>>>>
>>>>>
>>>>>
>>>>>     /**
>>>>>
>>>>>      * Concatenates two input string parameters and returns the
>>>>> result.
>>>>>
>>>>>      *
>>>>>
>>>>>      * @param s1
>>>>>
>>>>>      *            A string input
>>>>>
>>>>>      * @param s2
>>>>>
>>>>>      *            A string input
>>>>>
>>>>>      * @return The string result which consists of two input strings,
>>>>> with
>>>>> the second input string linked to the end of
>>>>>
>>>>>      *         the first input string
>>>>>
>>>>>      */
>>>>>
>>>>>     public String concatenateTwoStrings( String s1, String s2 ) {
>>>>>
>>>>>         return s1 + s2;
>>>>>
>>>>>
>>>>>
>>>>>     }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> Thank you!
>>>
>>>
>>> http://blogs.deepal.org
>>> http://deepal.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Problem-with-Runtime.getRuntime%28%29-exec-tp24064489p24095313.html
>> Sent from the Axis - User mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-Runtime.getRuntime%28%29-exec-tp24064489p24099683.html
Sent from the Axis - User mailing list archive at Nabble.com.


Mime
View raw message