• Post Reply Bookmark Topic Watch Topic
  • New Topic

whitespace in java  RSS feed

 
sachin kishan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam trying to build a string which is used to run the shell script.
for example: String path = "shellscript"+" "+string1+" "+string2+" "+string3;

but the problem is i need string2 to be blanc (space)
so string2 = " ";
unix is not accepting that white space and taking string3 value into string2..

any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Please don't post the same question to more than one forum; see our explanation here. I've deleted the other copy of this thread.

As to your question: same as you'd do it on the command line: by using a quoted or escaped blank string. Two single quotes ought to do fine.

Alternatively, there are forms over Runtime.exec() which take arrays of Strings as arguments, rather than a single String; use one of those. This will allow you to pass an empty String as an argument. Again, this is what you'd typically do when calling exec() from a C program.
[ January 02, 2007: Message edited by: Ernest Friedman-Hill ]
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should quote the parameters,

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could quote the parameters, but it is ugly and error-prone. Use one of the multi-argument versions of Runtime.exec(), like the wise Sheriff said earlier.

Also, a version using quoting is likely to be OS-specific, whereas using the multi-argument Runtime.exec() will be OS-independent. Of course, the command you are running may be OS-specific anyway...
[ January 08, 2007: Message edited by: Peter Chase ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More good advice about using Runtime,exec can be found here: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!