comparison lisp/process.el @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 1f50e6fe4f3f
children b8cc9ab3f761
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
31 ;; This file is dumped with XEmacs. 31 ;; This file is dumped with XEmacs.
32 32
33 ;;; Code: 33 ;;; Code:
34 34
35 35
36 (defvar binary-process-output)
37 (defvar buffer-file-type)
38
39 (defgroup processes nil 36 (defgroup processes nil
40 "Process, subshell, compilation, and job control support." 37 "Process, subshell, compilation, and job control support."
41 :group 'external 38 :group 'external
42 :group 'development) 39 :group 'development)
43 40
113 and returns a numeric exit status or a signal description string. 110 and returns a numeric exit status or a signal description string.
114 If you quit, the process is first killed with SIGINT, then with SIGKILL if 111 If you quit, the process is first killed with SIGINT, then with SIGKILL if
115 you quit again before the process exits." 112 you quit again before the process exits."
116 (let ((temp 113 (let ((temp
117 (make-temp-name 114 (make-temp-name
118 (concat (file-name-as-directory (temp-directory)) 115 (concat (file-name-as-directory (temp-directory)) "emacs"))))
119 (if (memq system-type '(ms-dos windows-nt)) "em" "emacs")))))
120 (unwind-protect 116 (unwind-protect
121 (progn 117 (progn
122 (if (memq system-type '(ms-dos windows-nt)) 118 (write-region start end temp nil 'silent)
123 (let ((buffer-file-type binary-process-output))
124 (write-region start end temp nil 'silent))
125 (write-region start end temp nil 'silent))
126 (if deletep (delete-region start end)) 119 (if deletep (delete-region start end))
127 (apply #'call-process program temp buffer displayp args)) 120 (apply #'call-process program temp buffer displayp args))
128 (ignore-file-errors (delete-file temp))))) 121 (ignore-file-errors (delete-file temp)))))
129 122
130 123
297 with any buffer 290 with any buffer
298 Third arg is program file name. It is searched for as in the shell. 291 Third arg is program file name. It is searched for as in the shell.
299 Remaining arguments are strings to give program as arguments." 292 Remaining arguments are strings to give program as arguments."
300 (apply 'start-process-internal name buffer program program-args)) 293 (apply 'start-process-internal name buffer program program-args))
301 294
302 (defun open-network-stream (name buffer host service) 295 (defun open-network-stream (name buffer host service &optional protocol)
303 "Open a TCP connection for a service to a host. 296 "Open a TCP connection for a service to a host.
304 Returns a subprocess-object to represent the connection. 297 Returns a subprocess-object to represent the connection.
305 Input and output work as for subprocesses; `delete-process' closes it. 298 Input and output work as for subprocesses; `delete-process' closes it.
306 Args are NAME BUFFER HOST SERVICE. 299 Args are NAME BUFFER HOST SERVICE.
307 NAME is name for process. It is modified if necessary to make it unique. 300 NAME is name for process. It is modified if necessary to make it unique.
310 an output stream or filter function to handle the output. 303 an output stream or filter function to handle the output.
311 BUFFER may be also nil, meaning that this process is not associated 304 BUFFER may be also nil, meaning that this process is not associated
312 with any buffer 305 with any buffer
313 Third arg is name of the host to connect to, or its IP address. 306 Third arg is name of the host to connect to, or its IP address.
314 Fourth arg SERVICE is name of the service desired, or an integer 307 Fourth arg SERVICE is name of the service desired, or an integer
315 specifying a port number to connect to." 308 specifying a port number to connect to.
316 (open-network-stream-internal name buffer host service)) 309 Fifth argument PROTOCOL is a network protocol. Currently 'tcp
310 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
311 supported. When omitted, 'tcp is assumed.
312
313 Ouput via `process-send-string' and input via buffer or filter (see
314 `set-process-filter') are stream-oriented. That means UDP datagrams are
315 not guaranteed to be sent and received in discrete packets. (But small
316 datagrams around 500 bytes that are not truncated by `process-send-string'
317 are usually fine.) Note further that UDP protocol does not guard against
318 lost packets."
319 (open-network-stream-internal name buffer host service protocol))
317 320
318 (defun shell-quote-argument (argument) 321 (defun shell-quote-argument (argument)
319 "Quote an argument for passing as argument to an inferior shell." 322 "Quote an argument for passing as argument to an inferior shell."
320 (if (eq system-type 'ms-dos) 323 (if (eq system-type 'windows-nt)
321 ;; MS-DOS shells don't have quoting, so don't do any. 324 (nt-quote-process-args (list shell-file-name argument))
322 argument 325 ;; Quote everything except POSIX filename characters.
323 (if (eq system-type 'windows-nt) 326 ;; This should be safe enough even for really weird shells.
324 (concat "\"" argument "\"") 327 (let ((result "") (start 0) end)
325 ;; Quote everything except POSIX filename characters. 328 (while (string-match "[^-0-9a-zA-Z_./]" argument start)
326 ;; This should be safe enough even for really weird shells. 329 (setq end (match-beginning 0)
327 (let ((result "") (start 0) end) 330 result (concat result (substring argument start end)
328 (while (string-match "[^-0-9a-zA-Z_./]" argument start) 331 "\\" (substring argument end (1+ end)))
329 (setq end (match-beginning 0) 332 start (1+ end)))
330 result (concat result (substring argument start end) 333 (concat result (substring argument start)))))
331 "\\" (substring argument end (1+ end))) 334
332 start (1+ end))) 335 (defun shell-command-to-string (command)
333 (concat result (substring argument start)))))) 336 "Execute shell command COMMAND and return its output as a string."
334
335 (defun exec-to-string (command)
336 "Execute COMMAND as an external process and return the output of that
337 process as a string"
338 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu>
339 (with-output-to-string 337 (with-output-to-string
340 (call-process shell-file-name nil t nil shell-command-switch command))) 338 (call-process shell-file-name nil t nil shell-command-switch command)))
341 339
342 (defalias 'shell-command-to-string 'exec-to-string) 340 (defalias 'exec-to-string 'shell-command-to-string)
343 341
344 ;;; process.el ends here 342 ;;; process.el ends here