Quotation in System.Process.system for Windows
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- haskell
調査の方向性
libraries/process/System/Process/Internals.hs の commandToProcess から始め、issue に記載されている引用符付きおよび引用符なしの Windows cmd.exe の例を再現します。System.Process.system が引用符付きのコマンド名と引数、および単純な cmd.exe を処理し、同時に issue に記載されている他の例も維持できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Moved from https://ghc.haskell.org/trac/ghc/ticket/5376:
Wagnerdm writes: I had a bit of fun recently tracking down quoting issues with the "system" command in Windows. For the examples below, I'll consistently use "Windows> " as the beginning of some text sent to the Windows command prompt cmd.exe, and use "GHC> " as the beginning of some text sent to a ghci session running in cmd.exe with System.Cmd imported.
The situation is this: I want to hand off a command line which has both a possibly-quoted command name and a (definitely) quoted argument. For concreteness, let's use "more" as the command and "foo.txt" as the argument, so that you can follow along at home on your favorite Windows system.
Windows> echo foo > foo.txt
Windows> "more" "foo.txt"
foo
All good so far. But:
GHC> system "\"more\" \"foo.txt\""
'more" "foo.txt' is not recognized as an internal or external command, operable program or batch file.
ExitFailure 1
After some digging, I discovered that system is shipping out to cmd /c, and indeed:
Windows> cmd /c "more" "foo.txt"
'more" "foo.txt' is not recognized as an internal or external command, operable program or batch file.
I don't know what the right fix is. However, after a bit of playing around, I discovered the following:
Windows> cmd /c ""more" "foo.txt""
foo
GHC> system "\"\"more\" \"foo.txt\"\""
foo
ExitSuccess
Wrapping commands with an extra pair of double-quotes this way seemed to give behavior matching the bare cmd.exe for all the examples I could think of, even ones I thought it would break. For example:
GHC> system "\"more foo.txt\""
foo
ExitSuccess
If this turns out to be the right thing to do, it's pretty easy to implement. In the commandToProcess function, at libraries/process/System/Process/Internals.hs:455, the change is just
- return (cmd, translate cmd ++ "/c " ++ string)
+ return (cmd, translate cmd ++ "/c \"" ++ string ++ "\"")
(And in any case, the examples above should answer this amusing comment, immediately following those lines:
-- We don't want to put the cmd into a single
-- argument, because cmd.exe will not try to split it up. Instead,
-- we just tack the command on the end of the cmd.exe command line,
-- which partly works. There seem to be some quoting issues, but
-- I don't have the energy to find+fix them right now (ToDo). --SDM
-- (later) Now I don't know what the above comment means. sigh.
Later, Brandon comments: What that comment means is that how CMD.EXE handles spaces is Windows-version-dependent. On the other hand, I think it's mostly consistent between XP and Windows 7 --- and I feel sorry for anyone forced to use an older version.
- 主要言語
- Haskell
- スター
- 91
- フォーク
- 93
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
haskell/process のほかの issue
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
HAVE_PIPE2 at compile time but not at runtime causes segfault on macOS対応中かも @alt-romes が 3 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
posix_spawn falls back to fork() when create_group = True due to HAVE_DECL_ macro mismatch対応中かも @lei-jia-xing が 11 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
haskell/process の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
haskell/bytestring#730 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
seal-harness/seal-harness#399 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
fmidue/codeworld-tasks#124 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
reflex-frp/reflex#563 ·