Comments (8)
Great! I look forward to seeing what interesting programs you come up with!
from script.
That's a good suggestion! How do you envisage this looking from the code point of view? What script
pipeline would you write to get real-time output?
from script.
One possibility would be:
script.Exec("ping -c 100 www.google.com").Stream()
and the implementation could just use StdoutPipe() and StderrPipe() of package os.exec, something along the lines of (didn't check the source of script.Exec, this code doesn't follow script's design with Pipe, it is just to give an idea):
cmd := exec.Command(...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
scanOut := bufio.NewScanner(stdout)
for scanOut.Scan() {
line := scanOut.Text()
if line != "" {
fmt.Println(line)
}
}
scanErr := bufio.NewScanner(stderr)
for scanErr.Scan() {
line := scanErr.Text()
if line != "" {
fmt.Println(line)
}
}
// maybe here we need something smarter and collect the errors so that we always call cmd.Wait()
if err := scanOut.Err(); err != nil {
return err
}
if err := scanErr.Err(); err != nil {
return err
}
if err := cmd.Wait(); err != nil {
return err
}
from script.
That sounds promising! Do you want to put a PR together along these lines so we can try it out?
from script.
Now implemented in v0.19.0.
from script.
Has this actually been implemented? I see that the PR was closed and not merged, and I don't see anything in the docs around streaming of output.. is this still something that would be implemented in time? It would be really helpful to have a Go variant of something like Python's subprocess
from script.
Yes, indeed. Here's what the README says:
Note that filters run concurrently, rather than producing nothing until each stage has fully read its input. This is convenient for executing long-running comands, for example. If you do need to wait for the pipeline to complete, call
Wait
.
The canonical example is something like OP's:
script.Exec("ping -c 100 www.google.com").Stdout()
But, as I say, all filters are now concurrent, including Exec
. Try it!
from script.
Thank you for the reply - yes indeed, I can see the output is concurrent - I'm running a sonobuy test using Exec()
, and the output is streamed to the console 👍
from script.
Related Issues (20)
- Bytes and String methods inconsistent on non-zero exist status from Exec HOT 1
- gitignore entry for Intellij IDEA HOT 4
- Feature Request: Add FilterFunc HOT 2
- Basename introduces a line feed HOT 1
- How can I check the progress of a script.Exec() command? HOT 2
- Interaction with bubbletea HOT 10
- Propose adding a delimeter to Column()
- Add Base64 encode and decode methods HOT 3
- Suggestion: `./go-script -c 'script.Stdin()...'` tool for running these HOT 5
- Should `ExecForEach` sanitize or escape arguments differently? HOT 9
- Parameterize a script.Pipe with a user data struct ? HOT 5
- Execv function HOT 1
- how to get the stdout of the Exec result? HOT 3
- Race condition in Pipe.Exec HOT 1
- Methods for mkdir and touch HOT 2
- Conditinally execute statements. HOT 2
- How to create folder, delete folder and list folder contents ? HOT 4
- Feature Suggestion: Fields HOT 4
- Makefile replacement HOT 2
- Expand prompt logic for PR #199
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from script.