common exec

classic Classic list List threaded Threaded
6 messages Options
kkk
Reply | Threaded
Open this post in threaded view
|

common exec

kkk
Hi:
I want to know can the common exec can handle the command with double
quotation?
For example ,I have a cmd as following:
*r.gisenv set="LOCATION=al"
file=HF5:"OMI-Aura_L3-OMTO3e_2009m0729_v003-2009m0731t020127.he5"://HDFEOS/GRIDS/OMI_Column_Amount_O3/Data_Fields/ColumnAmountO3
*
There are some double quotation in the command, I should use the
string.replace() to change the " to \", but it may cause some upexpected
problem,so I want to know if the common exec can do it ?
Reply | Threaded
Open this post in threaded view
|

Re: common exec

Siegfried Goeschl
Hi,

I think checking the FAQ might help :

http://commons.apache.org/exec/faq.html#complex-quoting

Cheers,

Siegfried Goeschl


On 02.03.10 02:59, maven apache wrote:

> Hi:
> I want to know can the common exec can handle the command with double
> quotation?
> For example ,I have a cmd as following:
> *r.gisenv set="LOCATION=al"
> file=HF5:"OMI-Aura_L3-OMTO3e_2009m0729_v003-2009m0731t020127.he5"://HDFEOS/GRIDS/OMI_Column_Amount_O3/Data_Fields/ColumnAmountO3
> *
> There are some double quotation in the command, I should use the
> string.replace() to change the " to \", but it may cause some upexpected
> problem,so I want to know if the common exec can do it ?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

kkk
Reply | Threaded
Open this post in threaded view
|

Re: common exec

kkk
2010/3/2 Siegfried Goeschl <[hidden email]>

> Hi,
>
> I think checking the FAQ might help :
>
> http://commons.apache.org/exec/faq.html#complex-quoting
>
> Cheers,
>
Thanks, I have checked the faq, however I am not sure the usage.So I woner
if there are some examplse?

>
> Siegfried Goeschl
>
>
>
> On 02.03.10 02:59, maven apache wrote:
>
>> Hi:
>> I want to know can the common exec can handle the command with double
>> quotation?
>> For example ,I have a cmd as following:
>> *r.gisenv set="LOCATION=al"
>>
>> file=HF5:"OMI-Aura_L3-OMTO3e_2009m0729_v003-2009m0731t020127.he5"://HDFEOS/GRIDS/OMI_Column_Amount_O3/Data_Fields/ColumnAmountO3
>> *
>> There are some double quotation in the command, I should use the
>> string.replace() to change the " to \", but it may cause some upexpected
>> problem,so I want to know if the common exec can do it ?
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: common exec

Siegfried Goeschl
+) Check out http://commons.apache.org/exec/xref-test/index.html and
CommandLine Test

+) CommandLine.add() allows to add arguments with/without quoting magic

Siegfried Goeschl

On 02.03.10 12:13, maven apache wrote:

> 2010/3/2 Siegfried Goeschl<[hidden email]>
>
>> Hi,
>>
>> I think checking the FAQ might help :
>>
>> http://commons.apache.org/exec/faq.html#complex-quoting
>>
>> Cheers,
>>
> Thanks, I have checked the faq, however I am not sure the usage.So I woner
> if there are some examplse?
>
>>
>> Siegfried Goeschl
>>
>>
>>
>> On 02.03.10 02:59, maven apache wrote:
>>
>>> Hi:
>>> I want to know can the common exec can handle the command with double
>>> quotation?
>>> For example ,I have a cmd as following:
>>> *r.gisenv set="LOCATION=al"
>>>
>>> file=HF5:"OMI-Aura_L3-OMTO3e_2009m0729_v003-2009m0731t020127.he5"://HDFEOS/GRIDS/OMI_Column_Amount_O3/Data_Fields/ColumnAmountO3
>>> *
>>> There are some double quotation in the command, I should use the
>>> string.replace() to change the " to \", but it may cause some upexpected
>>> problem,so I want to know if the common exec can do it ?
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

kkk
Reply | Threaded
Open this post in threaded view
|

Re: common exec

kkk
I meet a strange problem, a cmd can be executed in the command line ,however
can not be in the code using common exec. codes are:
---------------------------------------------------------------------------------------------
public class Grass {
public static String grassBatJob="GRASS_BATCH_JOB";
public void run(String cmd,String jobPath) {
//set the environments variables
Map<String, String> env=new HashMap<String, String>();
env.put(grassBatJob, jobPath);
 String gisDataBase="/home/kk/grass/GrassDataBase";
String location="spearfish60";
String mapset="PERMANENT";
cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
CommandLine line=new CommandLine(cmd);
//the real cmd should be >>grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT
System.out.println("start line=="+line.toString());
DefaultExecutor de=new DefaultExecutor();
try {
int index=de.execute(line,env);
System.out.println(index);
} catch (ExecuteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String jobPath=Grass.class.getResource("grass.sh").getFile();
new Grass().run("grass64 -text", jobPath);
}
}
-----------------------------------------------------------------------------------
The real cmd I want to execute is "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment
variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in
my application I got the exception"
--------------------
java.io.IOException: Cannot run program "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException:
error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at
org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
at org.kingxip.Grass.run(Grass.java:27)
at org.kingxip.Grass.main(Grass.java:38)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file
or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 7 more
--------------------
I wonder why?
2010/3/2 Siegfried Goeschl <[hidden email]>

> +) Check out http://commons.apache.org/exec/xref-test/index.html and
> CommandLine Test
>
> +) CommandLine.add() allows to add arguments with/without quoting magic
>
> Siegfried Goeschl
>
>
> On 02.03.10 12:13, maven apache wrote:
>
>> 2010/3/2 Siegfried Goeschl<[hidden email]>
>>
>>  Hi,
>>>
>>> I think checking the FAQ might help :
>>>
>>> http://commons.apache.org/exec/faq.html#complex-quoting
>>>
>>> Cheers,
>>>
>>>  Thanks, I have checked the faq, however I am not sure the usage.So I
>> woner
>> if there are some examplse?
>>
>>
>>> Siegfried Goeschl
>>>
>>>
>>>
>>> On 02.03.10 02:59, maven apache wrote:
>>>
>>>  Hi:
>>>> I want to know can the common exec can handle the command with double
>>>> quotation?
>>>> For example ,I have a cmd as following:
>>>> *r.gisenv set="LOCATION=al"
>>>>
>>>>
>>>> file=HF5:"OMI-Aura_L3-OMTO3e_2009m0729_v003-2009m0731t020127.he5"://HDFEOS/GRIDS/OMI_Column_Amount_O3/Data_Fields/ColumnAmountO3
>>>> *
>>>> There are some double quotation in the command, I should use the
>>>> string.replace() to change the " to \", but it may cause some upexpected
>>>> problem,so I want to know if the common exec can do it ?
>>>>
>>>>
>>>>  ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
kkk
Reply | Threaded
Open this post in threaded view
|

Fwd: common exec

kkk
I meet a strange problem, a cmd can be executed in the command line ,however
can not be in the code using common exec. codes are:
---------------------------------------------------------------------------------------------
public class Grass {
public static String grassBatJob="GRASS_BATCH_JOB";
public void run(String cmd,String jobPath) {
 //set the environments variables
Map<String, String> env=new HashMap<String, String>();
 env.put(grassBatJob, jobPath);
 String gisDataBase="/home/kk/grass/GrassDataBase";
 String location="spearfish60";
String mapset="PERMANENT";
 cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
CommandLine line=new CommandLine(cmd);
 //the real cmd should be >>grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT
System.out.println("start line=="+line.toString());
 DefaultExecutor de=new DefaultExecutor();
try {
int index=de.execute(line,env);
 System.out.println(index);
} catch (ExecuteException e) {
e.printStackTrace();
 } catch (IOException e) {
e.printStackTrace();
}
 }
public static void main(String[] args) {
String jobPath=Grass.class.getResource("grass.sh").getFile();
 new Grass().run("grass64 -text", jobPath);
}
}
-----------------------------------------------------------------------------------
The real cmd I want to execute is "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment
variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in
my application I got the exception"
--------------------
java.io.IOException: Cannot run program "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException:
error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
 at
org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
 at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
 at org.kingxip.Grass.run(Grass.java:27)
at org.kingxip.Grass.main(Grass.java:38)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file
or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
 at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
 ... 7 more
--------------------
I wonder why?