Mercurial > hg > xemacs-beta
comparison lisp/process.el @ 371:cc15677e0335 r21-2b1
Import from CVS: tag r21-2b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:03:08 +0200 |
parents | 4f79e16b1112 |
children | d883f39b8495 |
comparison
equal
deleted
inserted
replaced
370:bd866891f083 | 371:cc15677e0335 |
---|---|
243 ;; No prefix argument: put the output in a temp buffer, | 243 ;; No prefix argument: put the output in a temp buffer, |
244 ;; replacing its entire contents. | 244 ;; replacing its entire contents. |
245 (let ((buffer (get-buffer-create | 245 (let ((buffer (get-buffer-create |
246 (or output-buffer "*Shell Command Output*"))) | 246 (or output-buffer "*Shell Command Output*"))) |
247 (success nil) | 247 (success nil) |
248 (exit-status nil) | |
249 (directory default-directory)) | 248 (directory default-directory)) |
250 (unwind-protect | 249 (unwind-protect |
251 (if (eq buffer (current-buffer)) | 250 (if (eq buffer (current-buffer)) |
252 ;; If the input is the same buffer as the output, | 251 ;; If the input is the same buffer as the output, |
253 ;; delete everything but the specified region, | 252 ;; delete everything but the specified region, |
254 ;; then replace that region with the output. | 253 ;; then replace that region with the output. |
255 (progn (setq buffer-read-only nil) | 254 (progn (setq buffer-read-only nil) |
256 (delete-region (max start end) (point-max)) | 255 (delete-region (max start end) (point-max)) |
257 (delete-region (point-min) (max start end)) | 256 (delete-region (point-min) (max start end)) |
258 (setq exit-status | 257 (call-process-region (point-min) (point-max) |
259 (call-process-region (point-min) (point-max) | 258 shell-file-name t t nil |
260 shell-file-name t t nil | 259 shell-command-switch command) |
261 shell-command-switch command)) | |
262 (setq success t)) | 260 (setq success t)) |
263 ;; Clear the output buffer, | 261 ;; Clear the output buffer, |
264 ;; then run the command with output there. | 262 ;; then run the command with output there. |
265 (save-excursion | 263 (save-excursion |
266 (set-buffer buffer) | 264 (set-buffer buffer) |
267 (setq buffer-read-only nil) | 265 (setq buffer-read-only nil) |
268 ;; XEmacs change | 266 ;; XEmacs change |
269 (setq default-directory directory) | 267 (setq default-directory directory) |
270 (erase-buffer)) | 268 (erase-buffer)) |
271 (setq exit-status | 269 (call-process-region start end shell-file-name |
272 (call-process-region start end shell-file-name | 270 nil buffer nil |
273 nil buffer nil | 271 shell-command-switch command) |
274 shell-command-switch command)) | |
275 (setq success t)) | 272 (setq success t)) |
276 ;; Report the amount of output. | 273 ;; Report the amount of output. |
277 (let ((lines (save-excursion | 274 (let ((lines (save-excursion |
278 (set-buffer buffer) | 275 (set-buffer buffer) |
279 (if (= (buffer-size) 0) | 276 (if (= (buffer-size) 0) |
281 (count-lines (point-min) (point-max)))))) | 278 (count-lines (point-min) (point-max)))))) |
282 (cond ((= lines 0) | 279 (cond ((= lines 0) |
283 (if success | 280 (if success |
284 (display-message | 281 (display-message |
285 'command | 282 'command |
286 (if (eql exit-status 0) | 283 "(Shell command completed with no output)")) |
287 "(Shell command succeeded with no output)" | |
288 "(Shell command failed with no output)"))) | |
289 (kill-buffer buffer)) | 284 (kill-buffer buffer)) |
290 ((and success (= lines 1)) | 285 ((and success (= lines 1)) |
291 (message "%s" | 286 (message "%s" |
292 (save-excursion | 287 (save-excursion |
293 (set-buffer buffer) | 288 (set-buffer buffer) |
348 (defun exec-to-string (command) | 343 (defun exec-to-string (command) |
349 "Execute COMMAND as an external process and return the output of that | 344 "Execute COMMAND as an external process and return the output of that |
350 process as a string" | 345 process as a string" |
351 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> | 346 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> |
352 (with-output-to-string | 347 (with-output-to-string |
353 (call-process shell-file-name nil t nil shell-command-switch command))) | 348 (call-process shell-file-name nil t nil "-c" command))) |
354 | 349 |
355 (defalias 'shell-command-to-string 'exec-to-string) | 350 (defalias 'shell-command-to-string 'exec-to-string) |
356 | 351 |
357 ;;; process.el ends here | 352 ;;; process.el ends here |