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

Serge Aleynikov serge@REDACTED
Mon Feb 12 18:58:18 CET 2007


You made me curious to look at the sources to see if this happens 
indeed, but it seems that filename:nativename/1 only does path 
normalization and doesn't do name mangling:

filename.erl:545
================

nativename(Name0) ->
     Name = join([Name0]),			%Normalize.
     case os:type() of
	{win32, _} -> win32_nativename(Name);
	_          -> Name
     end.

win32_nativename([$/|Rest]) ->
     [$\\|win32_nativename(Rest)];
win32_nativename([C|Rest]) ->
     [C|win32_nativename(Rest)];
win32_nativename([]) ->
     [].

Serge

Eric P. Melbardis wrote:
> With r10 & windows platform, you can use
> 
> filename:nativename(FullPathName)
> 
> works the best, since the file name mangling is dynamic! (ie relative to
> other similar file names!)
> 
> regards
> 
> 
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Serge
> Aleynikov
> Sent: Monday, February 12, 2007 5:44 AM
> To: Denis Bilenko
> Cc: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] how to open_port with spaces in path?
> 
> Since this seems to be a known bug, you may try some workarounds.  The 
> most obvious one is to rename a directory so that it doesn't contain 
> spaces.  The less obvious one is to find out what is the "short name" of
> 
> a directory, and use that instead:
> 
> c:\temp>dir /X /AD "a*"
> 
>   Volume in drive C is unlabeled      Serial number is 381F:4FF1
>   Directory of  C:\temp\a*
> 
>   2/12/07   8:31         <DIR>    AA0919~1        a a
>                0 bytes in 0 files and 1 dir
>    3,814,490,112 bytes free
> 
> In the example above "AA0919~1" is the equivalent name of the "a a" 
> directory:
> 
> c:\temp>dir "AA0919~1"
> 
>   Volume in drive C is unlabeled      Serial number is 381F:4FF1
>   Directory of  C:\temp\AA0919~1\*
> 
>   2/12/07   8:31         <DIR>    .
>   2/12/07   8:31         <DIR>    ..
>   2/12/07   8:31               0  my.exe
>                0 bytes in 1 file and 2 dirs    0 bytes allocated
>    3,814,490,112 bytes free
> 
> Serge
> 
> P.S. This second workaround doesn't seem very appealing, but if you 
> can't possibly change directory names, this may be your only option.
> 
> Denis Bilenko wrote:
>> Hello,
>> 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.
>>
>> Googling revealed this:
>> Known problems
>>   * os:cmd on WIN32 does not always catch the output from the executed
> program
>>     correctly. There is also a problem with executing programs with
>> space in the path.
>> http://www.erlang.org/doc/doc-4.8.2/erts-4.8.2/notes_history.html
>>
>> It was not fixed? Are there any workarounds?
>>
>> erl: 5.5.3
>> os: winxp
>>
>> /Denis.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 

-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464



More information about the erlang-questions mailing list