2012-09-17 2 views
1

나는 쉘 명령을 실행하려면 다음 함수를 사용쉘 명령의 디렉토리를 지정할 수 있습니까?

예를 들어
(defun sh (cmd) 
    #+clisp (shell cmd) 
    #+ecl (si:system cmd) 
    #+sbcl (sb-ext:run-program "/bin/sh" (list "-c" cmd) :input nil :output*standard-output*) 
    #+clozure (ccl:run-program "/bin/sh" (list "-c" cmd) :input nil :output*standard-output*))) 

, 어떻게 명령 python -m CGIHTTPServer의 현재 디렉토리를 지정?

감사합니다.

+0

한 가지 방법은 스크립트가 현재 디렉토리에서 실행되기 때문에 실행 전에 디렉토리로 cd하는 것입니다. – keyser

+0

'(probe-file #P "./")'어때? – sbenitezb

+0

(프로브 파일 #P "./")는 쉘 명령을 실행할 때 변경하고자하는 현재 디렉토리를 리턴합니다. 이제 스크립트를 사용하여 쉘 명령을 래핑 한 다음 지정된 디렉토리에'cd '할 수있는 스크립트를 실행합니다. –

답변

3

ECL에서는 SYSTEM 앞에 EXT : CHDIR을 사용할 수 있습니다. default-pathname-defaults과 운영 체제 및 C 라이브러리가 이해하는 현재 디렉토리의 값을 모두 변경합니다.

BTW : (: 실행 프로그램 "명령"리스트의 인자들 EXT) 대신

0

더 이식성이 효과적으로 설정 것이다, 경로 이름 동적 *default-pathname-defaults* 바인딩을 사용하는 것입니다 귀하의 수 사용하는 경우 현재 작업 디렉토리. 오늘도 똑같은 문제가있었습니다.

(defun dot->png (filespec thunk) 
    "Save DOT information generated by a thunk on a *STANDARD-OUTPUT* to a FILESPEC file. Then use FILESPEC to create a corresponding png picture of a graph." 
    ;; dump DOT file first 
    (let ((*default-pathname-defaults* 
      (make-pathname :directory (pathname-directory (pathname filespec))))) 
    ;; (format t "pwd (curr working dir): ~A~%" *default-pathname-defaults*) 
    (with-open-file (*standard-output* 
        filespec 
        :direction :output 
        :if-exists :supersede) 
     (funcall thunk)) 
    #+sbcl 
    (sb-ext:run-program "/bin/sh" 
         (list "-c" (concatenate 'string "dot -Tpng -O " filespec)) 
         :input nil 
         :output *standard-output*) 
    #+clozure 
    (ccl:run-program "/bin/sh" 
        (list "-c" (concatenate 'string "dot -Tpng -O" filespec)) 
        :input nil 
        :output *standard-output*))) 

이가 건너 실행 비슷한 상황 &에서 사람에게 도움이 될 수 있다는 희망에 게시 됨 : 여기에 현재 작업 디렉토리를 지정 콘래드 Barski에 의해 리스프 텍스트의 땅에서 dot->png의 작업 적응이다 이 스레드.

관련 문제