Megatest

Diff
Login

Differences From Artifact [71a058a91c]:

To Artifact [833fe6b14b]:


74
75
76
77
78
79
80
81































    (let loop ((i 0))
      (let-values (((pid-val exit-status exit-code) (process-wait pid #t)))
         (if (eq? pid-val 0)
	     (begin
	       (thread-sleep! 2)
	       (loop (+ i 1)))
	     (values pid-val exit-status exit-code))))))
  






































|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    (let loop ((i 0))
      (let-values (((pid-val exit-status exit-code) (process-wait pid #t)))
         (if (eq? pid-val 0)
	     (begin
	       (thread-sleep! 2)
	       (loop (+ i 1)))
	     (values pid-val exit-status exit-code))))))

;;======================================================================
;; A persistent shell to which we can send many commands
;;    WATCH for flush issues!
;;    ALWAYS call with > /dev/null OR > logfile to cmd
;;======================================================================  
(define (cmdshell:make-shell cmd . params)
  ;; (print "Called with cmd=" cmd ", proc=" proc ", params=" params)
  (handle-exceptions
   exn
   (begin
     (print "ERROR:  Failed to run command: " cmd " " (string-intersperse params " "))
     #f)
   (let-values (((fh fho pid) (if (null? params)
				  (process cmd)
				  (process cmd params))))
      (vector fh fho pid))))

;; WARNING!! This will fail horribly if varname or varvalue have escaped or quoted portions
(define (cmdshell:set-env-var cmdshell varname varvalue)
  (with-output-to-port (vector-ref cmdshell 1)
    (lambda ()
      (print "export " varname "=" varvalue))))

(define (cmdshell:run-cmd cmdshell cmd)
  (with-output-to-port (vector-ref cmdshell 1)
    (lambda ()
      (print cmd))))

      ;; (close-input-port fh)
      ;;   (close-output-port fho)