【问题标题】:Execute command line from Scheme (Guile)从 Scheme (Guile) 执行命令行
【发布时间】:2016-01-17 13:42:06
【问题描述】:

问题在标题上有所描述,基本上我想从方案执行命令行,比如说'ls'并获取输出。所以我的问题是:

  • 有可能吗?
  • 怎么样?

提前非常感谢!

顺便说一句,我使用 Guille。

【问题讨论】:

    标签: command-line scheme guile


    【解决方案1】:

    您需要systemsystem* 之一。

    示例:(system "ls")

    来自文档:Guile Reference

    — 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")
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-21
    • 2011-05-05
    • 2012-07-15
    • 2017-07-04
    • 2011-06-15
    • 2012-08-03
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多