Update.
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
// nontest
|
||||
|
||||
import "pexpect" for Spawn
|
||||
import "timer" for Timer
|
||||
|
||||
System.print("Creating child")
|
||||
var child = Spawn.new("echo test")
|
||||
System.print("Child created, pid: %(child.pid)")
|
||||
System.print("isalive: %(child.isalive)")
|
||||
Timer.sleep(500)
|
||||
System.print("After sleep, isalive: %(child.isalive)")
|
||||
System.print("buffer: [%(child.buffer)]")
|
||||
child.close()
|
||||
System.print("Done")
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pexpect" for Spawn, Pexpect
|
||||
|
||||
var child = Spawn.new("echo 'hello world'")
|
||||
var result = child.expect(["world", "hello"])
|
||||
System.print(result) // expect: 1
|
||||
System.print(child.after) // expect: hello
|
||||
child.close()
|
||||
|
||||
child = Spawn.new("printf 'abc123def'")
|
||||
result = child.expectExact(["123"])
|
||||
System.print(result) // expect: 0
|
||||
System.print(child.before) // expect: abc
|
||||
System.print(child.after) // expect: 123
|
||||
child.close()
|
||||
|
||||
child = Spawn.new("echo 'test multiple patterns'")
|
||||
result = child.expect(["foo", "bar", "multiple"])
|
||||
System.print(result) // expect: 2
|
||||
child.close()
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pexpect" for Spawn, Pexpect
|
||||
|
||||
var child = Spawn.new("echo test")
|
||||
System.print(child.pid > 0) // expect: true
|
||||
System.print(child.timeout) // expect: 30
|
||||
child.timeout = 5
|
||||
System.print(child.timeout) // expect: 5
|
||||
System.print(child.maxread) // expect: 2000
|
||||
System.print(child.searchwindowsize) // expect: 0
|
||||
|
||||
child.expect(["test"])
|
||||
child.wait()
|
||||
System.print(child.exitstatus == 0) // expect: true
|
||||
child.close()
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
// nontest
|
||||
|
||||
import "pexpect" for Spawn
|
||||
import "timer" for Timer
|
||||
|
||||
System.print("1. Creating child")
|
||||
var child = Spawn.new("echo hello")
|
||||
|
||||
System.print("2. Sleeping 200ms")
|
||||
Timer.sleep(200)
|
||||
|
||||
System.print("3. Buffer: [%(child.buffer)]")
|
||||
System.print("4. isalive: %(child.isalive)")
|
||||
|
||||
System.print("5. Calling readNonblocking")
|
||||
var data = child.readNonblocking(100, 1)
|
||||
System.print("6. Data: [%(data)]")
|
||||
|
||||
System.print("7. Buffer after read: [%(child.buffer)]")
|
||||
System.print("8. Closing")
|
||||
child.close()
|
||||
System.print("Done")
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
// nontest
|
||||
|
||||
import "pexpect" for Spawn, Pexpect
|
||||
|
||||
System.print("Testing Pexpect.run")
|
||||
var output = Pexpect.run("echo test")
|
||||
System.print("Output: [%(output)]")
|
||||
System.print("Done")
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pexpect" for Spawn, Pexpect
|
||||
|
||||
var child = Spawn.new("echo hello")
|
||||
var result = child.expect(["hello"])
|
||||
System.print(result) // expect: 0
|
||||
|
||||
child = Spawn.new("cat")
|
||||
child.sendline("test input")
|
||||
var idx = child.expect(["test input"])
|
||||
System.print(idx) // expect: 0
|
||||
child.sendeof()
|
||||
child.close()
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pexpect" for Spawn, Pexpect
|
||||
|
||||
var child = Spawn.new("sleep 10")
|
||||
child.timeout = 0.5
|
||||
var result = child.expect(["never_match"])
|
||||
System.print(result) // expect: -2
|
||||
child.terminate(true)
|
||||
child.close()
|
||||
Reference in New Issue
Block a user