system and FilePath with space

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

system and FilePath with space

PICCA Frederic-Emmanuel
Hello

I try to execute a command using system.

my code is like this


system (unwords ["python",  p])

where
p :: FilePath
p = "/my super/script.py"


has you can see this path contain a space.
When I try to run it I get an error

python: can't open file '/my':

So the system command is wrong.
I understand that I need to escape the space  in the command, like this

p = "/my\ super/script.py"

now is there a function in haskell for this.
a sort of sanitizer for FilePath when used by system.

Thanks

Frederic
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: system and FilePath with space

Frerich Raabe
On 2017-01-26 10:50, PICCA Frederic-Emmanuel wrote:
> Hello
>
> I try to execute a command using system.
>
> my code is like this
>
>
> system (unwords ["python",  p])

An easier way to execute programs is to use the functions defined in
System.Process, e.g.:

import System.Process

main :: IO ()
main = callProcess "/usr/bin/python" ["/my super/script.py"]

Note that 'callProcess' takes a list of strings, each element being one
argument. The elements may contain spaces.

--
Frerich Raabe - [hidden email]
www.froglogic.com - Multi-Platform GUI Testing
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: system and FilePath with space

PICCA Frederic-Emmanuel
thanks but I do not have a recent enough ghc in order to use this method
(debian jessie)


maybe I can use proc in order to prepare my command line ?
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: system and FilePath with space

Michael Snoyman
You can use the rawSystem function on older versions of the process package.

On Thu, Jan 26, 2017 at 12:19 PM, PICCA Frederic-Emmanuel <[hidden email]> wrote:
thanks but I do not have a recent enough ghc in order to use this method
(debian jessie)


maybe I can use proc in order to prepare my command line ?
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: system and FilePath with space

PICCA Frederic-Emmanuel
>You can use the rawSystem function on older versions of the process package.

thanks , it is exactly what I wanted.

Cheers
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners