Java exec on Unix -


I have a Java code that is running on Unix (both AIX and Linux), but it does not work. If I run this code the file q1.01 is not compressed, and no exception has been thrown to me (file q1.01 is present, and I hope that after running the order q1.01.z file). Command Prompt If I type "which is abbreviated" it reports back with "/ usr / bin / compress" if I type "/ usr / bin / compress q1.01" command at the UNIX prompt, then it works fine Does anyone have any thoughts on what may be wrong?

  string cmd = "/ usr / bin / compress q1.01"; Runtime.getRuntime () Executive (cmd).  

[edit later: the problem was in the initial statement; OP was passing wildcard and not q.01. So apart from the part in bold my answer is wrong. I am saying that I am leaving it after comment.]

It is a program name without any argument Trying to run / usr / bin / compress .

The Runtime.exec () method has many variations. You are using the version, which just takes the executable, instead, you need to use the array version, which takes the string [1] in the string [0] in the parameters and parameters in the string [0].

wants a string array to pass the .exec () arguments.

Try

  string [] cmd = new string [] {"/ usr / bin / compress", "q1.01"}; Runtime.getRuntime () Executive (cmd).  

Note that .exec does not call the local command shell. This means that we have to parse the calling card.exec () before in addition to other things, wildcard extension and even some logic. This is the reason why you can not give it a complete command line


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -