@@ -6,18 +6,15 @@ import SystemPackage
66#endif
77
88import CLTLogger
9- import CMacroExports
109import Logging
1110import ProcessInvocation
11+ import StreamReader
1212
1313/* Old remark (fixed not):
1414 * Launch the manual test like so:
1515 * echo yolo | ./.build/debug/ManualTests
1616 * For some reasons actually typing stuff in the Terminal (no “echo yolo |”) does not work
17- * (probably some buffered read as stdin is not a tty for cat, or some other sh*t I don’t really get).
18- *
19- * Everything seems to work correctly when not sending file descriptors.
20- * If we do send fds, I’m not sure… */
17+ * (probably some buffered read as stdin is not a tty for cat, or some other sh*t I don’t really get). */
2118
2219
2320
@@ -34,7 +31,6 @@ let logger = Logger(label: "com.xcode-actions.manual-process-invocation-tests")
3431//let ptr = UnsafeMutableRawPointer.allocate(byteCount: 42, alignment: 1)
3532//print("yolo: \(read(stdin, ptr, 1))")
3633
37- //import StreamReader
3834//let reader = FileHandleReader(stream: FileHandle.standardInput, bufferSize: 30, bufferSizeIncrement: 30, underlyingStreamReadSizeLimit: 1)
3935//while let line = try reader.readLine()?.line {
4036// print(line.reduce("", { $0 + String(format: "%02x", $1) }))
6864// """, stdinRedirect: .none/*, fileDescriptorsToSend: [fd: fd]*/
6965// )
7066// let pi = ProcessInvocation("/bin/cat", stdinRedirect: .send(Data("yo".utf8)))
71- let pi = ProcessInvocation ( " /bin/cat " , stdinRedirect: . none( ) , stdoutRedirect: . none, stderrRedirect: . none, fileDescriptorsToSend: [ fd: fd] )
67+ // let pi = ProcessInvocation("/bin/cat", stdinRedirect: .none(), stdoutRedirect: .none, stderrRedirect: .none, fileDescriptorsToSend: [fd: fd])
68+ // for try await line in pi {
69+ // print("From cat: \(line.strLineOrHex())")
70+ // }
71+
72+ /* Try to read one line from ProcessInvocation and then one using StreamReader. */
73+ let pi = ProcessInvocation ( " head " , " -n " , " 1 " )
7274 for try await line in pi {
73- print ( " From cat: \( line. strLineOrHex ( ) ) " )
75+ print ( " From head: \( line. strLineOrHex ( ) ) " )
76+ }
77+ let reader = FileDescriptorReader ( stream: FileDescriptor . standardInput, bufferSize: 32 , bufferSizeIncrement: 16 , underlyingStreamReadSizeLimit: 1 )
78+ if let line = try reader. readLine ( ) ? . line {
79+ print ( " From reader: \( String ( data: line, encoding: . utf8) ?? line. reduce ( " " , { $0 + String( format: " %02x " , $1) } ) ) " )
80+ } else {
81+ print ( " Failed reading line from stream reader. " )
7482 }
7583} catch {
7684 print ( " Failed running the process: \( error) " )
0 commit comments