all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Win32 - how do I execute a shell command?
@ 2004-07-29 21:18 Paul Moore
  2004-07-29 21:36 ` Jason Rumney
  2004-07-30  7:15 ` Mathias Dahl
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Moore @ 2004-07-29 21:18 UTC (permalink / raw)


I have a Python script I want to execute and obtaing the stdout. In
XEmacs, I can do so simply using

    (shell-command-to-string (expand-file-name "~/fortune.py"))

This doesn't work in Gnu Emacs, basically because expand-file-name
returns filenames with *forward* slashes, which the shell doesn't
like.

OK, I could do a global replace of / with \, but that seems like a
hack. Is there a "expand file name in Win32 native format" (ie, with
backslashes) function?

Thanks,
Paul
-- 
A little inaccuracy sometimes saves tons of explanation -- Saki

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

* Re: Win32 - how do I execute a shell command?
  2004-07-29 21:18 Win32 - how do I execute a shell command? Paul Moore
@ 2004-07-29 21:36 ` Jason Rumney
  2004-07-30 19:43   ` Paul Moore
  2004-07-30  7:15 ` Mathias Dahl
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Rumney @ 2004-07-29 21:36 UTC (permalink / raw)


Paul Moore <pf_moore@yahoo.co.uk> writes:

> I have a Python script I want to execute and obtaing the stdout. In
> XEmacs, I can do so simply using
>
>     (shell-command-to-string (expand-file-name "~/fortune.py"))
>
> This doesn't work in Gnu Emacs, basically because expand-file-name
> returns filenames with *forward* slashes, which the shell doesn't
> like.

Are you sure the shell doesn't like the forward slashes? The Windows
command-line will not automatically execute Python scripts AFAIK, so
your command line will either have to start with the Python
interpretor, or "start ", which invokes the Explorer association.

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

* Re: Win32 - how do I execute a shell command?
  2004-07-29 21:18 Win32 - how do I execute a shell command? Paul Moore
  2004-07-29 21:36 ` Jason Rumney
@ 2004-07-30  7:15 ` Mathias Dahl
  1 sibling, 0 replies; 4+ messages in thread
From: Mathias Dahl @ 2004-07-30  7:15 UTC (permalink / raw)


Paul Moore <pf_moore@yahoo.co.uk> writes:

> I have a Python script I want to execute and obtaing the stdout. In
> XEmacs, I can do so simply using
> 
>     (shell-command-to-string (expand-file-name "~/fortune.py"))
> 
> This doesn't work in Gnu Emacs, basically because expand-file-name
> returns filenames with *forward* slashes, which the shell doesn't
> like.
> 
> OK, I could do a global replace of / with \, but that seems like a
> hack. Is there a "expand file name in Win32 native format" (ie, with
> backslashes) function?

I have found no such function so I use this:

 (defun slash-to-backslash (text)
   (substitute ?\\ ?/ text))

Also, as Jason tells you, you should either use cmd.exe's
start command, if the .py files is associated with the
correct program, or explicitly start it with the correct
interpreter.

Something like this should work (not tested);

(shell-command-to-string 
  (concat "python " (slash-to-backslash (expand-file-name "~/fortune.py"))))

/Mathias

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

* Re: Win32 - how do I execute a shell command?
  2004-07-29 21:36 ` Jason Rumney
@ 2004-07-30 19:43   ` Paul Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2004-07-30 19:43 UTC (permalink / raw)


jasonr (Jason Rumney) @  f2s.com writes:

> Are you sure the shell doesn't like the forward slashes?

Yes. If I replace forward slashes with backslashes, the command works
fine.

> The Windows command-line will not automatically execute Python
> scripts AFAIK, so your command line will either have to start with
> the Python interpretor, or "start ", which invokes the Explorer
> association.

Not true. Both CMD.EXE and 4NT (the shell I am using) have ways of
making Python files directly executable (the PATHEXT variable for CMD,
and executable extensions for 4NT).

The key point is that the *native* path separator is backslash on
Windows. Forward slash is supported in the Windows API as an
alternative, but it isn't native, and that causes problems.

Paul.
-- 
Instant gratification takes too long -- Carrie Fisher

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

end of thread, other threads:[~2004-07-30 19:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-29 21:18 Win32 - how do I execute a shell command? Paul Moore
2004-07-29 21:36 ` Jason Rumney
2004-07-30 19:43   ` Paul Moore
2004-07-30  7:15 ` Mathias Dahl

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.