* Executing bash bash script from emacs / elisp
@ 2010-09-03 9:20 Rainer M Krug
2010-09-03 11:09 ` Deniz Dogan
2010-09-03 11:44 ` Memnon Anon
0 siblings, 2 replies; 7+ messages in thread
From: Rainer M Krug @ 2010-09-03 9:20 UTC (permalink / raw)
To: help-gnu-emacs
Hi
I am a complete beginner concerning elisp - so please bear with me if
this is a simple question.
I would like to execute a shell (bash) script from elisp, which is then
called from org-babel to do some post-processing of the result of
tangling. Tangling in org-babel has a hook for post-processing, and I
know how to set it. Therefore I am simply looking for a way of executing
my shell script from that hook.
essentially:
this-function-executes-a-shell-script(The_Shell_Script.sh)
Thanks,
Rainer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
2010-09-03 9:20 Rainer M Krug
@ 2010-09-03 11:09 ` Deniz Dogan
2010-09-03 11:16 ` Rainer M Krug
2010-09-03 11:44 ` Memnon Anon
1 sibling, 1 reply; 7+ messages in thread
From: Deniz Dogan @ 2010-09-03 11:09 UTC (permalink / raw)
To: Rainer M Krug; +Cc: help-gnu-emacs
2010/9/3 Rainer M Krug <R.M.Krug@gmail.com>:
> Hi
> I am a complete beginner concerning elisp - so please bear with me if
> this is a simple question.
>
> I would like to execute a shell (bash) script from elisp, which is then
> called from org-babel to do some post-processing of the result of
> tangling. Tangling in org-babel has a hook for post-processing, and I
> know how to set it. Therefore I am simply looking for a way of executing
> my shell script from that hook.
>
> essentially:
>
> this-function-executes-a-shell-script(The_Shell_Script.sh)
>
> Thanks,
> Rainer
>
>
>
You want to look at the functions `call-process-shell-command' and
`call-process'.
Example:
(call-process-shell-command "the_shell_script.sh" nil nil nil "arg1" "arg2")
That's equivalent to running "the_shell_script.sh arg1 arg" in a shell.
--
Deniz Dogan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
2010-09-03 11:09 ` Deniz Dogan
@ 2010-09-03 11:16 ` Rainer M Krug
2010-09-03 11:42 ` Deniz Dogan
0 siblings, 1 reply; 7+ messages in thread
From: Rainer M Krug @ 2010-09-03 11:16 UTC (permalink / raw)
To: Deniz Dogan; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/09/10 13:09, Deniz Dogan wrote:
> 2010/9/3 Rainer M Krug <R.M.Krug@gmail.com>:
>> Hi
>> I am a complete beginner concerning elisp - so please bear with me if
>> this is a simple question.
>>
>> I would like to execute a shell (bash) script from elisp, which is then
>> called from org-babel to do some post-processing of the result of
>> tangling. Tangling in org-babel has a hook for post-processing, and I
>> know how to set it. Therefore I am simply looking for a way of executing
>> my shell script from that hook.
>>
>> essentially:
>>
>> this-function-executes-a-shell-script(The_Shell_Script.sh)
>>
>> Thanks,
>> Rainer
>>
>>
>>
>
> You want to look at the functions `call-process-shell-command' and
> `call-process'.
>
> Example:
> (call-process-shell-command "the_shell_script.sh" nil nil nil "arg1" "arg2")
>
> That's equivalent to running "the_shell_script.sh arg1 arg" in a shell.
>
Thanks a lot. After looking around I also found async-shell-command and
shell-command. Am I right in assuming that, as the script is not
producing any output, these commands are equivalent?
In addition, when using async-shell-command I get asked "A command is
running. Kill it? (yes or no)"
Is there any way to avoid this?
Cheers,
Rainer
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
Tel: +33 - (0)9 53 10 27 44
Cell: +27 - (0)8 39 47 90 42
Fax (SA): +27 - (0)8 65 16 27 82
Fax (D) : +49 - (0)3 21 21 25 22 44
Fax (FR): +33 - (0)9 58 10 27 44
email: Rainer@krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyA2RQACgkQoYgNqgF2egoyoACeL58SqUwn0qp71VpCGykKWwQW
3Z8AoIi+AmcmN9bPc1v4ExcU5nKeSatR
=QS8P
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
2010-09-03 11:16 ` Rainer M Krug
@ 2010-09-03 11:42 ` Deniz Dogan
2010-09-03 12:41 ` Rainer M Krug
0 siblings, 1 reply; 7+ messages in thread
From: Deniz Dogan @ 2010-09-03 11:42 UTC (permalink / raw)
To: R.M.Krug; +Cc: help-gnu-emacs
2010/9/3 Rainer M Krug <r.m.krug@gmail.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 03/09/10 13:09, Deniz Dogan wrote:
>> 2010/9/3 Rainer M Krug <R.M.Krug@gmail.com>:
>>> Hi
>>> I am a complete beginner concerning elisp - so please bear with me if
>>> this is a simple question.
>>>
>>> I would like to execute a shell (bash) script from elisp, which is then
>>> called from org-babel to do some post-processing of the result of
>>> tangling. Tangling in org-babel has a hook for post-processing, and I
>>> know how to set it. Therefore I am simply looking for a way of executing
>>> my shell script from that hook.
>>>
>>> essentially:
>>>
>>> this-function-executes-a-shell-script(The_Shell_Script.sh)
>>>
>>> Thanks,
>>> Rainer
>>>
>>>
>>>
>>
>> You want to look at the functions `call-process-shell-command' and
>> `call-process'.
>>
>> Example:
>> (call-process-shell-command "the_shell_script.sh" nil nil nil "arg1" "arg2")
>>
>> That's equivalent to running "the_shell_script.sh arg1 arg" in a shell.
>>
>
> Thanks a lot. After looking around I also found async-shell-command and
> shell-command. Am I right in assuming that, as the script is not
> producing any output, these commands are equivalent?
>
Those two functions are interactive, i.e. they can be called by the
user directly using e.g. M-x shell-command. Nothing stops you from
using them, but they both basically just wrap call-process in a bunch
of user interaction handling.
> In addition, when using async-shell-command I get asked "A command is
> running. Kill it? (yes or no)"
> Is there any way to avoid this?
>
Yes, it should be enough to simply set the OUTPUT-BUFFER argument to
nil to tell Emacs not to print the output anywhere, hence not creating
a buffer for the process.
--
Deniz Dogan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
2010-09-03 9:20 Rainer M Krug
2010-09-03 11:09 ` Deniz Dogan
@ 2010-09-03 11:44 ` Memnon Anon
1 sibling, 0 replies; 7+ messages in thread
From: Memnon Anon @ 2010-09-03 11:44 UTC (permalink / raw)
To: Rainer M Krug; +Cc: help-gnu-emacs
Hi,
Rainer M Krug <R.M.Krug@gmail.com> writes:
> essentially:
> this-function-executes-a-shell-script(The_Shell_Script.sh)
-- Function: call-process program &optional infile destination display
-- Function: call-process-shell-command command &optional infile
-- Function: start-process name buffer-or-name program &rest args
-- Function: start-process-shell-command name buffer-or-name command
Have a look at [ (info "(elisp)Processes") ].
Did that help?
Memnon
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
[not found] <mailman.4.1283506601.16808.help-gnu-emacs@gnu.org>
@ 2010-09-03 12:03 ` Pascal J. Bourguignon
0 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2010-09-03 12:03 UTC (permalink / raw)
To: help-gnu-emacs
Rainer M Krug <R.M.Krug@gmail.com> writes:
> I am a complete beginner concerning elisp - so please bear with me if
> this is a simple question.
>
> I would like to execute a shell (bash) script from elisp, which is then
> called from org-babel to do some post-processing of the result of
> tangling. Tangling in org-babel has a hook for post-processing, and I
> know how to set it. Therefore I am simply looking for a way of executing
> my shell script from that hook.
>
> essentially:
>
> this-function-executes-a-shell-script(The_Shell_Script.sh)
The problem is that hook functions are called with no argument, and
should modify the environment (the current buffer or whatever else
they want to modify).
Another problem is that buffers are more than just a sequence of
character: there are text annotation, properties, markers, etc.
In any case the scheme would be to write a hook function that would
gather all the information you want to send to the script, and to
serialize it into a temporary file or a temporary buffer, and to run
the shell script. Then collect the output of the shell script, and
deserialize it into modifications to the environment.
Hooks in org-babel-post-tangle-hook are called on a temporary buffer,
assuming you only want to process the characters and replace the
contents of that temporary buffer, you could use
shell-command-on-region to filter them.
(require 'cl)
(defun wrap-hook (shell-script)
(lexical-let ((shell-script shell-script))
(lambda ()
(shell-command-on-region (point-min) (point-max)
shell-script
t t "*errors*" t))))
(add-hook -example-hook (wrap-hook "ls"))
--
__Pascal Bourguignon__ http://www.informatimago.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Executing bash bash script from emacs / elisp
2010-09-03 11:42 ` Deniz Dogan
@ 2010-09-03 12:41 ` Rainer M Krug
0 siblings, 0 replies; 7+ messages in thread
From: Rainer M Krug @ 2010-09-03 12:41 UTC (permalink / raw)
To: Deniz Dogan; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/09/10 13:42, Deniz Dogan wrote:
> 2010/9/3 Rainer M Krug <r.m.krug@gmail.com>:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 03/09/10 13:09, Deniz Dogan wrote:
>>> 2010/9/3 Rainer M Krug <R.M.Krug@gmail.com>:
>>>> Hi
>>>> I am a complete beginner concerning elisp - so please bear with me if
>>>> this is a simple question.
>>>>
>>>> I would like to execute a shell (bash) script from elisp, which is then
>>>> called from org-babel to do some post-processing of the result of
>>>> tangling. Tangling in org-babel has a hook for post-processing, and I
>>>> know how to set it. Therefore I am simply looking for a way of executing
>>>> my shell script from that hook.
>>>>
>>>> essentially:
>>>>
>>>> this-function-executes-a-shell-script(The_Shell_Script.sh)
>>>>
>>>> Thanks,
>>>> Rainer
>>>>
>>>>
>>>>
>>>
>>> You want to look at the functions `call-process-shell-command' and
>>> `call-process'.
>>>
>>> Example:
>>> (call-process-shell-command "the_shell_script.sh" nil nil nil "arg1" "arg2")
>>>
>>> That's equivalent to running "the_shell_script.sh arg1 arg" in a shell.
>>>
>>
>> Thanks a lot. After looking around I also found async-shell-command and
>> shell-command. Am I right in assuming that, as the script is not
>> producing any output, these commands are equivalent?
>>
Dear Mannon and Deniz
Thanks a lot for your input.
>
> Those two functions are interactive, i.e. they can be called by the
> user directly using e.g. M-x shell-command. Nothing stops you from
> using them, but they both basically just wrap call-process in a bunch
> of user interaction handling.
OK - I understand
>
>> In addition, when using async-shell-command I get asked "A command is
>> running. Kill it? (yes or no)"
>> Is there any way to avoid this?
>>
>
> Yes, it should be enough to simply set the OUTPUT-BUFFER argument to
> nil to tell Emacs not to print the output anywhere, hence not creating
> a buffer for the process.
>
Thanks - I am using call-process-shell-command and if I set the BUFFER
to 0, it backgrounds as I want it
Cheers,
Rainer
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
Tel: +33 - (0)9 53 10 27 44
Cell: +27 - (0)8 39 47 90 42
Fax (SA): +27 - (0)8 65 16 27 82
Fax (D) : +49 - (0)3 21 21 25 22 44
Fax (FR): +33 - (0)9 58 10 27 44
email: Rainer@krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyA7OwACgkQoYgNqgF2egqGmQCcDWWvC4t1/liCgNtcb2twxmga
RV0AnAjoemamKaO2XqXDLLq7LhMSJvvr
=VuAy
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-09-03 12:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.4.1283506601.16808.help-gnu-emacs@gnu.org>
2010-09-03 12:03 ` Executing bash bash script from emacs / elisp Pascal J. Bourguignon
2010-09-03 9:20 Rainer M Krug
2010-09-03 11:09 ` Deniz Dogan
2010-09-03 11:16 ` Rainer M Krug
2010-09-03 11:42 ` Deniz Dogan
2010-09-03 12:41 ` Rainer M Krug
2010-09-03 11:44 ` Memnon Anon
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.