这个问题可以描述为如何从Scheme执行命令行,比如'ls'并获取输出。那么我的问题是:
- 这是否可行?
- 如何实现?
非常感谢您的提前帮助!
顺便说一下,我使用Guile。
这个问题可以描述为如何从Scheme执行命令行,比如'ls'并获取输出。那么我的问题是:
非常感谢您的提前帮助!
顺便说一下,我使用Guile。
你需要其中之一 system
或 system*
。
例如:(system "ls")
来自文档:Guile参考资料
— Scheme Procedure: system [cmd]
— C Function: scm_system (cmd)
Execute cmd using the operating system's “command processor”. Under Unix this is usually the default shell sh. The value returned is cmd's exit status as returned by waitpid, which can be interpreted using the functions above.
If system is called without arguments, return a boolean indicating whether the command processor is available.
— Scheme Procedure: system* . args
— C Function: scm_system_star (args)
Execute the command indicated by args. The first element must be a string indicating the command to be executed, and the remaining items must be strings representing each of the arguments to that command.
This function returns the exit status of the command as provided by waitpid. This value can be handled with status:exit-val and the related functions.
system* is similar to system, but accepts only one string per-argument, and performs no shell interpretation. The command is executed using fork and execlp. Accordingly this function may be safer than system in situations where shell interpretation is not required.
Example: (system* "echo" "foo" "bar")
system
如何处理输入、输出和错误流? - coredumpsystem
调用基本上直接调用了posix的system
。https://github.com/cky/guile/blob/stable-2.0/libguile/simpos.c#L65 - soegaard