2025-01-20 20:37:23 +00:00
|
|
|
import mem
|
|
|
|
import sys
|
|
|
|
|
|
|
|
main() {
|
|
|
|
length := 256
|
|
|
|
command := mem.alloc(length)
|
|
|
|
argv := mem.alloc(1)
|
|
|
|
envp := mem.alloc(1)
|
|
|
|
info := mem.alloc(24)
|
|
|
|
|
|
|
|
loop {
|
|
|
|
sys.write(1, "$ ", 2)
|
|
|
|
n := sys.read(0, command, length)
|
|
|
|
|
|
|
|
if n <= 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-01-24 21:47:28 +00:00
|
|
|
command[n-1] = '\0'
|
2025-01-20 20:37:23 +00:00
|
|
|
pid := sys.fork()
|
|
|
|
|
|
|
|
if pid == 0 {
|
|
|
|
sys.execve(command, argv, envp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.waitid(0, pid, info, 4)
|
|
|
|
}
|
|
|
|
}
|