0

I'm struggling with passing arguments read from the minibuffer to a shell command in a elisp function.

I've written the following so far:

(defun perlclean (review clean)
  "Script PERL blablabla"
  (interactive "Foriginal: \nFclean: ")
  (with-current-buffer
    (shell-command
      "perl -pe 's/\\q\{.*} ( \{ ( (?: [^}{]+ | (?1))*+ ) \} )/$2/gx' %s\\ \\>\\ %s" review clean)))

The idea is to pass the first file (called review) through this perl command to get the so-called clean file. I want to specify the name of both files (that could not exist, that's why I used F).

The present version of this script asks me for both paths/names but ended with Wrong type argument: stringp,255.

I work on Linux-Ubuntu.

1

2 Answers 2

1

There are a couple of problems here. You're using with-current-buffer, which expects its first argument to be either a buffer, or the name of a buffer. In your function, this will be the value returned by shell-command, which is neither a buffer or the name of a buffer.

You've also used the strings return and clean as the arguments for OUTPUT-BUFFER and ERROR-BUFFER. Neither of these variables are buffers or buffer names, so I'm not sure what you're expecting to happen here, but it's not surprising there's an error.

To answer your actual question, it's straightforward to collect arguments from the minibuffer and pass them to a shell command:

(defun perlclean (review clean)
  "Script PERL blablabla"
  (interactive "Foriginal: \nFclean: ")
  (shell-command (format "echo Review: %s Clean: %s" review clean)))

Running this command, you'll see the output of the echo command in the minibuffer, and also in a new buffer called * Shell Command Output*.

0

The error message is confusing, but you’re passing a string to something that expects something else.

Specifically, the shell-command function takes these arguments:

(shell-command COMMAND &optional OUTPUT-BUFFER ERROR-BUFFER)

It takes the command to run followed by two buffers to use for the output and any errors the command produces. You’re passing in strings instead of buffers.

I suspect that you wanted to interpolate those strings into the command, but shell-command doesn’t do that for you. I recommend using functions like shell-quote-argument or combine-and-quote-arguments to build the command. See chapter 38.2 Shell Arguments of the Emacs Lisp manual for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.