gpt4 book ai didi

command-line - 从 Scheme (Guile) 执行命令行

转载 作者:行者123 更新时间:2023-12-04 14:42:40 24 4
gpt4 key购买 nike

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

  • 是否可以?
  • 如何?

  • 非常感谢!

    顺便说一句,我使用Guille。

    最佳答案

    您需要其中之一 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")

    关于command-line - 从 Scheme (Guile) 执行命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33210533/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com