all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Quoting shell arguments in start-process; escaping " in strings
@ 2011-01-18  0:12 Leo Alekseyev
  2011-01-18  5:16 ` Leo Alekseyev
  0 siblings, 1 reply; 2+ messages in thread
From: Leo Alekseyev @ 2011-01-18  0:12 UTC (permalink / raw)
  To: help-gnu-emacs

I am trying to fix poor handling of links in org-mode under Windows.

I need to issue the following command using start-process (note the
space in file name):
$ bash -c "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
\"c:\\home\\leo\\tmp\\test spc.nb\""
;; This runs fine in M-x shell

I can't figure out how to quote the last argument properly when using
(start-process).  Can someone please enlighten me as to the proper
procedure?..  Here's what doesn't work:

- Trying to issue that command as written at the command prompt makes
the quotes disappear:
(start-process "test" nil "bash" "-c"
"c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
\"c:\\home\\leo\\tmp\\test spc.nb\"")

The effective command line becomes
c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE c:\home\leo\tmp\test
spc.nb (no quotes).

- Trying single quotes to protect the space, i.e.  (start-process
"test" nil "bash" "-c" "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
'c:\\home\\leo\\tmp\\test spc.nb'"), the effective command line
becomes c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
"c:\\home\\leo\\tmp\\test spc.nb" (quotes, but erroneous
double-backshlashes -- why?..  Shouldn't emacs convert \\ to \?..).

- Trying to escape both the backslashes and the quotation marks (the
result is verbatim \, missing "):
(start-process "test" nil "bash" "-c"
"c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
\\\"c:\\home\\leo\\tmp\\test spc.nb\\\"")
The effective command line becomes
c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE \c:\home\leo\tmp\test
spc.nb\

Is there a way to prevent (start-process) from stripping quotes under
all circumstance, which is what it seems to be doing?..
Note also that shell-quote-arguments *does not* do the right thing in
this example because I have to use a combination of Unix and DOS-style
paths.

--Leo



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Quoting shell arguments in start-process; escaping " in strings
  2011-01-18  0:12 Quoting shell arguments in start-process; escaping " in strings Leo Alekseyev
@ 2011-01-18  5:16 ` Leo Alekseyev
  0 siblings, 0 replies; 2+ messages in thread
From: Leo Alekseyev @ 2011-01-18  5:16 UTC (permalink / raw)
  To: help-gnu-emacs

Answering my own question here...  Since I'm doing bash -c at the
command line, the correct format is, of course,

(start-process "test" nil "bash" "-c" "bash -c
\"c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
\\\"c:\\home\\leo\\tmp\\test spc.nb\\\"\"")

Or, (start-process-shell-command "test" nil cmd) where cmd is the last
argument above.  This ugliness is what one has to resort to when
(w32-shell-execute...) fails on a particular group of files.

On Mon, Jan 17, 2011 at 7:12 PM, Leo Alekseyev <dnquark@gmail.com> wrote:
> I am trying to fix poor handling of links in org-mode under Windows.
>
> I need to issue the following command using start-process (note the
> space in file name):
> $ bash -c "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
> \"c:\\home\\leo\\tmp\\test spc.nb\""
> ;; This runs fine in M-x shell
>
> I can't figure out how to quote the last argument properly when using
> (start-process).  Can someone please enlighten me as to the proper
> procedure?..  Here's what doesn't work:
>
> - Trying to issue that command as written at the command prompt makes
> the quotes disappear:
> (start-process "test" nil "bash" "-c"
> "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
> \"c:\\home\\leo\\tmp\\test spc.nb\"")
>
> The effective command line becomes
> c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE c:\home\leo\tmp\test
> spc.nb (no quotes).
>
> - Trying single quotes to protect the space, i.e.  (start-process
> "test" nil "bash" "-c" "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
> 'c:\\home\\leo\\tmp\\test spc.nb'"), the effective command line
> becomes c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
> "c:\\home\\leo\\tmp\\test spc.nb" (quotes, but erroneous
> double-backshlashes -- why?..  Shouldn't emacs convert \\ to \?..).
>
> - Trying to escape both the backslashes and the quotation marks (the
> result is verbatim \, missing "):
> (start-process "test" nil "bash" "-c"
> "c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE
> \\\"c:\\home\\leo\\tmp\\test spc.nb\\\"")
> The effective command line becomes
> c:/PROGRA~1/WOLFRA~1/MATHEM~1/8.0/MATHEM~1.EXE \c:\home\leo\tmp\test
> spc.nb\
>
> Is there a way to prevent (start-process) from stripping quotes under
> all circumstance, which is what it seems to be doing?..
> Note also that shell-quote-arguments *does not* do the right thing in
> this example because I have to use a combination of Unix and DOS-style
> paths.
>
> --Leo
>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-18  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-18  0:12 Quoting shell arguments in start-process; escaping " in strings Leo Alekseyev
2011-01-18  5:16 ` Leo Alekseyev

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.