Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fork to shell script and terminate original process with Haskell

I am currently writing a Haskell program that does some initialization work and then calls ncmpcpp. What I am trying to do is start ncmpcpp and terminate the Haskell program, so that only ncmpcpp is left (optionally, the program can keep running in the background, as long as it's unintrusive)

However, even though I am able to start ncmpcpp, I cannot interact with it. I see its output, but input appears to be impossible.

What I am currently doing is:

import System.Process (createProcess, proc)
...
spawnCurses :: [String] -> IO ()
spawnCurses params = do 
  _ <- createProcess (proc "ncmpcpp" params)
  return ()

What am I doing wrong/What should I do differently?

like image 287
Sacchan Avatar asked Nov 06 '12 22:11

Sacchan


1 Answers

What you are trying to achieve sounds like what the exec family of functions does. Take a look at the executeFile function.

If you want your parent Haskell process to be still running after the child process is started read about fork-exec and the forkProcess function.

A complete example of using forkProcess together with executeFile can be found at http://therning.org/magnus/archives/727.

like image 103
Jan Avatar answered Sep 19 '22 04:09

Jan