Can not handle space in cmd passed in Runtime.getRuntime().exec() on LINUX

Hi,

I am trying to excute an exe fromjava program onLINUX. This exe takes a file as argument so that the exe can write some text in the file. But if a space comes in the path of file the problem occurs.

I clear it with my real case.

I am trying to execute these line

String cmdLine="\"/root/My Progs/out.exe \" +\"/root/out/out.txt"

Runtime.getRuntime().exec(cmdLine);

But it is not consideringMy Prog as a single directory instead looking for/root/My folder.

It says /root/My : not found

If i change the folderMy Prog toMyProg every thing goes fine.

what should i do to over come this problem ? Can any one help me?

thanks and regards,

rahul

[778 byte] By [rahulapva] at [2007-11-27 7:03:25]
# 1
Spaces are not encouraged in unix system file names/paths. It can just about cope, but generally put the file name in quotes.
malcolmmca at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 2
Quote your paths as "/root/My Progs/out.sh" (including the quotes)or'/root/My Progs/out.sh' (including the quotes)or/root/My\ Progs/out.shin Linux. One question though, does Linux execute .exe files? I doubt it unless you use WINE.
Jamwaa at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 3
This was just discussed here last week. http://forum.java.sun.com/thread.jspa?threadID=5173991
jverda at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 4
> This was just discussed here last week.We discuss it every week. We might make it twice this week :-).[EDIT]: Nobody posted the obligatory link: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
kevjavaa at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 5
> > This was just discussed here last week.> > We discuss it every week. Runtime.exec? Definitely. Spaces in Runtime.exec? I hadn't noticed.
jverda at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 6
> Spaces in Runtime.exec? I hadn't noticed.Ahh, apologies, missed the qualifier :).
kevjavaa at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...
# 7
I'm not going to repeat the whole of this very recent thread http://forum.java.sun.com/thread.jspa?threadID=5173991&messageID=9709486#9709486
sabre150a at 2007-7-12 18:54:37 > top of Java-index,Java Essentials,Java Programming...