Skip to content

Commit 5b6c316

Browse files
committed
add example of NewlineTransformer [skip ci]
1 parent a5af708 commit 5b6c316

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,27 @@ If the process could not be spawned please double-check that python can be launc
332332

333333
### NewlineTransformer
334334

335-
A utility class for splitting stream data into newlines. Used as the default for stdoutSplitter and stderrSplitter if they are unspecified. You can use this class for any extra python streams if you'd like.
335+
A utility class for splitting stream data into newlines. Used as the default for stdoutSplitter and stderrSplitter if they are unspecified. You can use this class for any extra python streams if you'd like. For example:
336+
337+
```python
338+
# foo.py
339+
print('hello world', file=open(3, "w"))
340+
```
341+
342+
```typescript
343+
import { PythonShell, NewlineTransformer, Options } from 'python-shell'
344+
345+
const options: Options = {
346+
'stdio':
347+
['pipe', 'pipe', 'pipe', 'pipe'] // stdin, stdout, stderr, custom
348+
}
349+
const pyshell = new PythonShell('foo.py', options)
350+
351+
const customPipe = pyshell.childProcess.stdio[3]
352+
customPipe.pipe(new NewlineTransformer()).on('data', (customResult: Buffer) => {
353+
console.log(customResult.toString())
354+
})
355+
```
336356

337357
## Used By:
338358

0 commit comments

Comments
 (0)