Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reposting ! string concatanation not working in java

807580Jan 22 2010 — edited Jan 23 2010
hi I am using the following code to construct a string and i see that it seems that the correct string is made but the application does not run
if i just cut n paste the same string into command prompt it works fine . please advise :
also note iam costructing string in two way , but using stringbuffer and by using , but both ways dont work.
If the parameter is just one word for example say "Testing" then the shell command works fine which tells me that the string concatanation is not working or embedding some special chars?

...
public static void main(String args[]) {
String s = null;
// system command to run
String quotes="\"";
String parameter = quotes args[0] quotes;
String cmd = "awtrap -f 10.200.16.17 -h 10.100.10.112 -p 162 -c fdot 1.3.6.1.4.1.791.2.9.2 6 4 1.3.6.1.4.1.791.2.9.2 -s " parameter;
System.out.println(cmd);
File workDir = new File("/opt/CA/SharedComponents/ccs/atech/services/bin");
StringBuffer sb = new StringBuffer();
sb.append("awtrap -f 10.200.16.17 -h 10.100.10.112 -p 162 -c fdot 1.3.6.1.4.1.791.2.9.2 6 4 1.3.6.1.4.1.791.2.9.2 -s ");
sb.append("\"");
sb.append(args[0]);
sb.append("\"");
String str2 = sb.toString();
System.out.println(str2);
try {
Process p = Runtime.getRuntime().exec(cmd, null, workDir);
....

========================================== below is the run log ============================================

awtrap -f 10.200.16.17 -h 10.100.10.112 -p 162 -c fdot 1.3.6.1.4.1.791.2.9.2 6 4 1.3.6.1.4.1.791.2.9.2 -s "testing 2"
awtrap -f 10.200.16.17 -h 10.100.10.112 -p 162 -c fdot 1.3.6.1.4.1.791.2.9.2 6 4 1.3.6.1.4.1.791.2.9.2 -s "testing 2"
usage: /opt/CA/SharedComponents/ccs/atech/services/bin/awtrap [-v 1 | 2c | 3] [-i] [-r retries] [-f from_addr | from_host]
[-h dest_addr | dest_host] [-p port] [-t timeout ] [-d logLevel]
[-c community] enterprise type [subtype] [oid oidtype value]


================================= now if I just cut n paste the string on command prompt it runs fine =====================

Pt$ awtrap -f 10.200.16.17 -h 10.100.10.112 -p 162 -c fdot 1.3.6.1.4.1.791.2.9.2 6 4 1.3.6.1.4.1.791.2.9.2 -s "testing 2"
Pt$
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2010
Added on Jan 22 2010
16 comments
283 views