gaucheのsystem該当の関数はprocess-output->stringと思ったがcall-with-input-processの方が良い
gaucheのsystem該当の関数は(call-with-input-process "コマンド" port->string)で決まり
>>(regexp-replace-all #/\n/ (call-with-input-process "echo -e 'a\nb\nc\n'" port->string) " , ") =>a , b , c , ,
gaucheのsystem該当の関数はprocess-output->stringなんだがどうも改行コードの扱いが変みたいだ。
process-output->string-listでは認識している改行コードがprocess-output->stringでは単なるスペースになってる?
Function: process-output->string command &keyword error encoding conversion-buffer-size on-abnormal-exit
Function: process-output->string-list command &keyword error encoding conversion-buffer-size on-abnormal-exitcommand を実行し、その(標準出力への)出力を回収して返します。 process-output->string は command からの全ての出力を連結し 1つの文字列とします。その際、空白文字からなるシーケンスは1つの空白に 置換されます。このアクションは、シェルスクリプトにおける「コマンド置換」 に似たものです。 process-output->string-list は command からの出力を行ごとに 回収し、それらをリストにしたものを返します。改行文字は削除されます。
内部的には、command は call-with-input-process により 実行されます。キーワード引数はcall-with-input-processに そのまま渡されます。
>>(use gauche.process) =>#<undef> >>(print (process-output->string-list "echo -e 'a b c'")) (a b c) =>#<undef> >>(print (process-output->string-list "echo -e 'a\nb\nc\n'")) (a b c ) =>#<undef> >>(for-each print (process-output->string-list "echo -e 'a b c'")) a b c =>#<undef> >>(for-each print (process-output->string-list "echo -e 'a\nb\nc\n'")) a b c =>#<undef> >>(print (process-output->string "echo -e 'a\nb\nc\n'")) a b c =>#<undef>
process-output->string-listは改行を削除することが書いてあるが・・・もしや改行コードは空白文字に該当するの?>空白文字からなるシーケンスは1つの空白に 置換されます。
やっぱりそうだった
>>(display "a\nb\nc\n") a b c =>#<undef> >>(regexp-replace-all #/\s/ "a\nb\nc\n" "x") =>axbxcx