<p>How do I create a background process with Haskell on windows without a visible command window being created?</p>

<p>I wrote a Haskell program that runs backup processes periodically but every time I run it, a command window opens up to the top of all the windows. I would like to get rid of this window. What is the simplest way to do this?</p>

[{'answer_id': 51049, 'author': 'Apocalisp', 'author_id': 3434, 'author_profile': 'https://Stackoverflow.com/users/3434', 'pm_score': 0, 'selected': False, 'text': '<p>The simplest way I can think of is to run the rsync command from within a Windows Shell script (vbs or cmd).</p>\n'}, {'answer_id': 51980, 'author': 'Martin Del Vecchio', 'author_id': 5397, 'author_profile': 'https://Stackoverflow.com/users/5397', 'pm_score': 0, 'selected': False, 'text': '<p>I don\'t know anything about Haskell, but I had this problem in a C project a few months ago.</p>\n\n<p>The best way to execute an external program without any windows popping up is to use the ShellExecuteEx() API function with the "open" verb.  If ShellExecuteEx() is available to you in Haskell, then you should be able to achieve what you want.</p>\n\n<p>The C code looks something like this:</p>\n\n<pre><code>SHELLEXECUTEINFO Info;\nBOOL b;\n\n// Execute it\nmemset (&amp;Info, 0, sizeof (Info));\nInfo.cbSize = sizeof (Info);\nInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;\nInfo.hwnd = NULL;\nInfo.lpVerb = "open";\nInfo.lpFile = "rsync.exe";\nInfo.lpParameters = "whatever parameters you like";\nInfo.lpDirectory = NULL;\nInfo.nShow = SW_HIDE;\nb = ShellExecuteEx (&amp;Info);\nif (b)\n   {\n   // Looks good; if there is an instance, wait for it\n   if (Info.hProcess)\n      {\n      // Wait\n      WaitForSingleObject (Info.hProcess, INFINITE);\n      }\n   }\n</code></pre>\n'}, {'answer_id': 52342, 'author': 'Alasdair', 'author_id': 2654, 'author_profile': 'https://Stackoverflow.com/users/2654', 'pm_score': 3, 'selected': False, 'text': '<p>You should really tell us how you are trying to do this currently, but on my system (using linux) the following snippet will run a command without opening a new terminal window. It should work the same way on windows.</p>\n\n<pre><code>module Main where\nimport System\nimport System.Process\nimport Control.Monad\n\nmain :: IO ()\nmain = do\n  putStrLn "Running command..."\n  pid &lt;- runCommand "mplayer song.mp3" -- or whatever you want\n  replicateM_ 10 $ putStrLn "Doing other stuff"\n  waitForProcess pid &gt;&gt;= exitWith\n</code></pre>\n'}, {'answer_id': 58228, 'author': 'airportyh', 'author_id': 5304, 'author_profile': 'https://Stackoverflow.com/users/5304', 'pm_score': 3, 'selected': False, 'text': '<p>Thanks for the responses so far, but I\'ve found my own solution. I did try a lot of different things, from writing a vbs script as suggested to a standalone program called hstart. hstart worked...but it creates a separate process which I didn\'t like very much because then I can\'t kill it in the normal way. But I found a simpler solution that required simply Haskell code.</p>\n\n<p>My code from before was a simple call to runCommand, which did popup the window. An alternative function you can use is <a href="http://hackage.haskell.org/packages/archive/process/1.0.0.0/doc/html/System-Process.html#v%3ArunProcess" rel="nofollow noreferrer">runProcess</a> which has more options. From peeking at the ghc source code file runProcess.c, I found that the CREATE_NO_WINDOW flag is set when you supply redirects for all of STDIN, STOUT, and STDERR. So that\'s what you need to do, supply redirects for those. My test program looks like:</p>\n\n<pre><code>import System.Process\nimport System.IO\nmain = do\n  inH &lt;- openFile "in" ReadMode\n  outH &lt;- openFile "out" WriteMode\n  runProcess "rsync.bat" [] Nothing Nothing (Just inH) (Just outH) (Just outH)\n</code></pre>\n\n<p>This worked! No command window again! A caveat is that you need an empty file for inH to read in as the STDIN eventhough in my situation it was not needed.</p>\n'}]
['https://Stackoverflow.com/questions/51028', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5304/']