2015-10-19 56 views
3

問題在標題中描述,基本上我想從scheme執行命令行,讓我們說'ls'並獲取輸出。所以我的問題是:從Scheme(Guile)執行命令行

  • 這可能嗎?
  • 如何?

非常感謝!

順便說一句,我用Guille。

回答

2

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

如何輸入,輸出和錯誤流通過'system'處理? – coredump

+1

我不認爲它們受到影響 - Guile'系統'或多或少地直接調用posix'系統'。 https://github.com/cky/guile/blob/stable-2.0/libguile/simpos.c#L65 – soegaard