i can not find a solution for getting separately stdout and stderr using subprocess or command in racket.
with subprocess i get nothing and command i find this solution on the internet:
What are you trying to achieve? I ask because I have only used this in practice once before, with an external Python script.
But basically, you get the ports for the subprocess using:
(define-values (sp out in err)
(subprocess #false #false #false
. apply .
PYTHON-PATH script-path script-args))
And then you use those as you would normally use ports. This is an old piece of code, so it is kind of a mess:
; I think input is supposed to be triggered by a command from the user
(define (script-ready input)
(cond [(and (ports-open?) (process-running?))
(match input
['close
; send the close instruction to the script
(displayln close?
in)
(flush-output in)
; close the ports and wait for the process to terminate
(and (close-ports) (subprocess-wait sp))
#;successful-close 'closed]
[((? string?)
. and .
(app string->bytes/utf-8 text-bytes))
; send the number of bytes for the script to read next
(displayln (bytes-length text-bytes)
in)
(flush-output in)
; send the bytes to the script
(write-bytes text-bytes
in)
(flush-output in)
; apply the port-reader procedure
(on-read out input)]
[else
#;unrecognised-input #false])]
[else
(error 'script-ready
(string-append
"encountered unexpectedly closed port or terminated subprocess:\n"
"`in` closed?: ~a, `out` closed?: ~a, `err` closed?: ~a, `sp` status: ~a")
(port-closed? in) (port-closed? out) (port-closed? err)
(subprocess-status sp))]))
I apologize if this is not what you're looking for, though.
i wanted to /bin/rm -f files of previous computations, and your code ,remind me that me too i'm launching python code after the /bin/rm -f files and it worked in python (admit i did not test the stderr because there is no error perheaps)
The problem was i used -f in /bin/rm that discard ALL errors so it was normal to have nothing in stderr.
i will rewrite all with subprocess , currently the problem is that /bin/rm -f file can not find file because the current path is not fixed.
i have to fix all that and retest, thanks for your help.
For info here is the scratchy code, but do not take it in consideration ,i have to fix all that:
I wouldn't launch an external process for that; Racket has functions to get the lists of files in directories and delete files. Just use them. See 15.2 Filesystem
subprocess, system, and similar document how they use ports pretty thoroughly, including the use of current-output-port, etc.: 15.4 Processes
You could parameterize those, or use subprocess-returned ports for something more parallel; but for the case you mentioned, I second using Racket’s (more portable) filesystem constructs.
thanks for the help, both subprocess and process* works now, for deleting i will use filesystems when i update the code. Do not know what was really blocking the process, suddenly it worked all the ways: Racket code is between PHP and Python, and the PHP code is ugly and Python is slow (have to add ini_set('default_socket_timeout', 600); in the PHP soap client too)