• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

whitespace in java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should quote the parameters,

 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic