Skip to content

Commit

Permalink
add example of NewlineTransformer [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Mar 27, 2021
1 parent a5af708 commit 5b6c316
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,27 @@ If the process could not be spawned please double-check that python can be launc

### NewlineTransformer

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.
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:

```python
# foo.py
print('hello world', file=open(3, "w"))
```

```typescript
import { PythonShell, NewlineTransformer, Options } from 'python-shell'

const options: Options = {
'stdio':
['pipe', 'pipe', 'pipe', 'pipe'] // stdin, stdout, stderr, custom
}
const pyshell = new PythonShell('foo.py', options)

const customPipe = pyshell.childProcess.stdio[3]
customPipe.pipe(new NewlineTransformer()).on('data', (customResult: Buffer) => {
console.log(customResult.toString())
})
```

## Used By:

Expand Down

0 comments on commit 5b6c316

Please sign in to comment.