Closed Konstantin8105 closed 5 years ago
example see #155
I'll take this! PR coming later today.
How to run test for that issue:
go test -v -tags=integration -run=TestIntegrationScripts/tests/stdlib.c
go test -v -run=TestCSTD
Try simplify code like that: https://blog.kowalczyk.info/article/wOYk/advanced-command-execution-in-go-with-osexec.html
cmd := exec.Command("ls", "-lah")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
That site is the example that I worked from, but I found that this only shows the output after the command finishes, which is not how the system
function in C works. For example, a loop/other long running command will never show any output if we follow this example.
Saw this example on another site. It simply forces the output from the exec'd command to go directly to your stdout/stderr. No need to capture in a buffer and print it out after, and there is no delay in output.
cmd := exec.Command("ls", "-lah")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
Dear @JalonSolov , feel free for creating PR.
Add test and implementation on Go for function
stdlib.h
system
Description: https://en.cppreference.com/w/c/program/system File for test code add :c4go/tests/stdlib.c