emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>
To: Max Nikulin <manikulin@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-maxima.el: Fix execution on MS Windows
Date: Thu, 30 Dec 2021 23:54:10 +0300	[thread overview]
Message-ID: <8cd49b4c-9342-a77f-d665-402c41432b57@gmail.com> (raw)
In-Reply-To: <sqkn1p$l8c$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]

> When some external data is substituted into a Maxima command 
> (batchload this case) there should be an extra pass of escaping that 
> protects special characters like quotes (and backslashes?) accordingly 
> to Maxima rules. 
Not necessarily, Maxima is capable of understanding unescaped paths, for 
example, this works:

maxima --very-quiet -r "batchload(\"/tmp/sp 
ce/babel-gxqTkM/maxima-ua3e9j.max\")"$

> I suspect that quotes your added around %S must not be used there. Due 
> to them file name appears outside of quotes at all. 
Yes, good catch.

> Unsure concerning Maxima but usually it is possible to pass arguments 
> avoiding quoting issues for particular language.
Command line Maxima actually has a batch flag, but using it returns the 
entire input file in the output too and that seems to be the reason why 
the original authors of ob-maxima didn't use it. It's probably possible 
to filter that on our side, but such filtering would require extra work, 
which they probably deemed unnecessary, for such a rather obscure set of 
use cases.

Anyway, I've tried to get it to work using shell-quote-argument, see the 
attached patch. Seems to work well enough in practice on both platforms 
and for cases like (setq temporary-file-directory "/tmp/`echo hi`/").

[-- Attachment #2: 0001-ob-maxima.el-Fix-execution-on-MS-Windows.patch --]
[-- Type: text/plain, Size: 1288 bytes --]

From 47690d14ac4838d8e39f08bd8224f0b4af053359 Mon Sep 17 00:00:00 2001
From: Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>
Date: Sun, 26 Dec 2021 22:47:19 +0300
Subject: [PATCH] ob-maxima.el: Fix execution on MS Windows

* ob-maxima.el (org-babel-execute:maxima): Change command line
invocation to a one that should work everywhere.
---
 lisp/ob-maxima.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el
index 7b49bb07a..08b586414 100644
--- a/lisp/ob-maxima.el
+++ b/lisp/ob-maxima.el
@@ -77,8 +77,11 @@ This function is called by `org-babel-execute-src-block'."
 	(result
 	 (let* ((cmdline (or (cdr (assq :cmdline params)) ""))
 		(in-file (org-babel-temp-file "maxima-" ".max"))
-		(cmd (format "%s --very-quiet -r 'batchload(%S)$' %s"
-			     org-babel-maxima-command in-file cmdline)))
+		(cmd (format "%s --very-quiet -r %s$ %s"
+			     org-babel-maxima-command
+                             (shell-quote-argument
+                              (format "batchload(%S)" in-file))
+                             cmdline)))
 	   (with-temp-file in-file (insert (org-babel-maxima-expand body params)))
 	   (message cmd)
            ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' "
-- 
2.34.1.windows.1


  reply	other threads:[~2021-12-30 20:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-26 20:18 Nikolay Kudryavtsev
2021-12-29 17:05 ` Max Nikulin
2021-12-29 18:37   ` Nikolay Kudryavtsev
2021-12-30 16:33     ` Max Nikulin
2021-12-30 20:54       ` Nikolay Kudryavtsev [this message]
2022-01-11 13:55         ` Max Nikulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8cd49b4c-9342-a77f-d665-402c41432b57@gmail.com \
    --to=nikolay.kudryavtsev@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    --subject='Re: [PATCH] ob-maxima.el: Fix execution on MS Windows' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).