3 Commits

4 changed files with 7 additions and 8 deletions

2
cmd.v
View File

@@ -272,7 +272,7 @@ pub fn (mut c Command) start() !int {
} }
} }
if c.ctx != none && c.cancel != none { if c.ctx != none {
printdbg('${@METHOD}: start watching for context') printdbg('${@METHOD}: start watching for context')
go c.ctx_watch() go c.ctx_watch()
} }

View File

@@ -11,16 +11,17 @@ fn main() {
mut cmd := runcmd.with_context(ctx, 'sleep', '120') mut cmd := runcmd.with_context(ctx, 'sleep', '120')
// Start a command. // Start a command.
started := time.now()
println('Start command at ${started}')
cmd.start()! cmd.start()!
started := time.now()
println('Command started at ${started}')
// Wait for command. // Wait for command.
cmd.wait()! cmd.wait()!
// The `sleep 120` command would run for two minutes without a timeout. // The `sleep 120` command would run for two minutes without a timeout.
// But in this example, it will time out after 10 seconds. // But in this example, it will time out after 10 seconds.
println('Command finished after ${time.now() - started}') finished := time.now()
println('Command finished at ${finished} after ${finished - started}')
// Since command has been terminated, the state would be: `signal: 15 (SIGTERM)` // Since command has been terminated, the state would be: `signal: 15 (SIGTERM)`
println('Child state: ${cmd.state}') println('Child state: ${cmd.state}')

View File

@@ -1,4 +1,3 @@
import io.string_reader
import strings import strings
import runcmd import runcmd
@@ -6,12 +5,11 @@ fn main() {
input := 'Hello from parent process!' input := 'Hello from parent process!'
// Prepare reader and writer. // Prepare reader and writer.
//
// * `reader` reads input from the parent process; it will be copied to the // * `reader` reads input from the parent process; it will be copied to the
// standard input of the child process. // standard input of the child process.
// * `writer` accepts data from the child process; it will be copied from the // * `writer` accepts data from the child process; it will be copied from the
// standard output of the child process. // standard output of the child process.
mut reader := string_reader.StringReader.new(reader: runcmd.buffer(input.bytes()), source: input) mut reader := runcmd.buffer(input.bytes())
mut writer := strings.new_builder(4096) mut writer := strings.new_builder(4096)
// Prepare the command. // Prepare the command.

2
v.mod
View File

@@ -1,7 +1,7 @@
Module { Module {
name: 'runcmd' name: 'runcmd'
description: 'Run external commands' description: 'Run external commands'
version: '0.2.0' version: '0.2.1'
license: 'Unlicense' license: 'Unlicense'
repo_url: 'https://github.com/gechandesu/runcmd' repo_url: 'https://github.com/gechandesu/runcmd'
dependencies: [] dependencies: []