开发者

Linux terminal: How to pass an argument to another argument

I have a system program that runs other programs in a special environment: cset shield -e PROGRAM. Now to run a java program, I typed cset shield -e java PROGRAM, but that doesn't work. It turns out that I have to specify the full path of java. However, PATH is set, so on its own java PROGRAM works. Is there any easier way to do this?

In addition, another java program of mine requires external libraries and开发者_JAVA百科 runs fine by itself. But with cset shield, I got NoClassDefFoundError, which means that it cannot find the libraries. Adding the classpath argument (-cp CLASSPATH) resulted in the error message "p" contains invalid characters: p.


After trying out the various suggestions and their permutations, I hit upon a way that half-works: cset shield --exec -- $(which java) -cp ./:<LIB_PATH>/DA_LIB.jar PROGRAM. But with this I'm getting UnsatisfiedLinkError: Library not found: DA_LIB


You could try which to locate java:

cset shield -e $(which java) PROGRAM

This will run java under the special environment, not in a sub shell. (which will run in a sub shell, obviously).

To fix the CLASSPATH issue: I cannot test it here but you probably can try this:

cset shield -e "$(which java) -cp <CLASSPATH> PROGRAM"

Where <CLASSPATH> needs to be replaced with the actual classpath.


cset shield -e $(java PROGRAM)

subshell $() seems to work better then backticks `` for shell substitution (run command inside and return stdout)

for more info see

http://tldp.org/LDP/abs/html/commandsub.html


Have you tried the following?

cset shield -e `java PROGRAM`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜