[erlang-questions] how to open_port with spaces in path?

Robert Raschke rrerlang@REDACTED
Mon Feb 12 10:28:16 CET 2007


Denis Bilenko wrote:
> I'm trying to execute external program which happened to have spaces in
> path (not uncommon on windows). open_port exits with einval:
> 
> 56> open_port({spawn, "D:/a a/my.exe"}, []).
> 
> =ERROR REPORT==== 11-Feb-2007::23:59:35 ===
> Error in process <0.102.0> with exit value:
> {einval,[{erlang,open_port,[{spawn,"D:/a a/my.exe"},[]]},{erl_eval
> ,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
> 
> ** exited: {einval,[{erlang,open_port,[{spawn,"D:/a a/my.exe"},[]]},
>                     {erl_eval,do_apply,5},
>                     {shell,exprs,6},
>                     {shell,eval_loop,3}]} **
> 
> I've tried to use quotes
> 
> 57> open_port({spawn, "\"D:/a a/my.exe\""}, []).
> 
> it doesn't change anything.
> 

I have not tried this with Erlang, so it may very well not do any
good.  But in other applications, where I have to execute an external
program on Windows, I have a brute force approach.  I double quote
every thing that is meant to be one entity (or argument), and then to
execute it I double quote the whole lot.  Thus

C:\Program Files\MyProg\myprog.exe arg1 "arg 2 and some" arg3

gets passed to the Windows bit as

""C:\Program Files\MyProg\myprog.exe arg1" "arg 2 and some" "arg3""

If I remember correctly the initial double double qoute makes the
Windows cmd enter into some special way of reading the rest of the
command.  I have forgotten where I picked that up though.  Sorry.

Robby

--
r dot raschke at tombob dot com





More information about the erlang-questions mailing list