Quotation in System.Process.system for Windows
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- haskell
- Domaine
- operating-systems
Piste de recherche
Commencez dans libraries/process/System/Process/Internals.hs, au niveau de commandToProcess, puis reproduisez les exemples Windows cmd.exe entre guillemets et sans guillemets cités dans l’issue. Le travail est terminé lorsque System.Process.system gère les noms de commandes et les arguments entre guillemets ainsi qu’un simple cmd.exe, tout en conservant les autres exemples décrits dans l’issue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Haskell
- Étoiles
- 91
- Forks
- 93
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de haskell/process
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
-
HAVE_PIPE2 at compile time but not at runtime causes segfault on macOSPeut-être pris @alt-romes l’a pris il y a 3 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
-
posix_spawn falls back to fork() when create_group = True due to HAVE_DECL_ macro mismatchPeut-être pris @lei-jia-xing l’a pris il y a 11 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 57/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
Toutes les issues de haskell/process
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
haskell/bytestring#730 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
seal-harness/seal-harness#399 ·
Les mainteneurs répondent en général sous 1 jour
-
add previously overlooked rulesOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
fmidue/codeworld-tasks#124 ·
-
allow haskell-src-exts-1.24Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
reflex-frp/reflex#563 ·