Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9035657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:48:32+00:00 2026-06-16T08:48:32+00:00

On a UNIX-like system with GHC installed, I can create an file with the

  • 0

On a UNIX-like system with GHC installed, I can create an file with the following contents

#!/usr/bin/env runhaskell
main = putStrLn "Hello, I am a UNIX script file."

Make the file executable, and this executes the given Haskell code.

How do I do the equivalent in a Windows .bat file?

Preferably, no extra files are created, no environment variables are set, it also works if the batch file is accessed using a UNC path or a path containing spaces, the Haskell namespace is not polluted, and a reasonable behavior results if the Haskell code contains errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:48:33+00:00Added an answer on June 16, 2026 at 8:48 am

    After much trial and error, this turns out to be possible. I have designed the following:

    @(set /p =-- < nul & type "%~f0") | runhaskell & exit /b
    main = putStrLn "Hello, I am a Windows batch file."
    

    The only disadvantage of this mechanism is that error messages contain the name of a temp file created by (something called by) runhaskell.

    Here is a full explanation of how this works:

    • set /p =-- < nul outputs -- (and two irrelevant spaces) not followed by a newline. This works like this:
      • set /p ANSWER=Please enter answer: prints Please enter answer: without a newline, waits for user input, and puts that in environment variable ANSWER.
      • < nul acts as if the user did not enter anything.
      • As an (undocumented?) special case, the environment variable name can be left out, and then no environment variable is set.
    • "%~f0" is the name of the current batch file.
    • Therefore set /p =-- < nul & type "%~f0" outputs the current batch file, but with the first line commented out (when interpreted as Haskell code).
    • We pipe this into runhaskell, which (undocumentedly?) interprets its stdin as non-literal (!) Haskell code.
      • Like in the UNIX version in the question, this assumes that runhaskell is on the current PATH.
    • Finally, exit makes sure that everything after the first line is not seen by the Windows batch file interpreter, and exit /b makes sure that we only exit this script, not any surrounding cmd.exe shell.
    • And the leading @ makes sure that all this gibberish is not echoed when running this script.

    (I have not found a way to do the same for literate Haskell code; but I don’t have a need for that currently.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a new unix command to automatically list the contents
The UNIX sort command can sort a very large file like this: sort large_file
I'd like to play with Unix system calls, ideally from Ruby. How can I
I'm looking for virtual file system for Windows like FUSE for Unix, Are there
I am trying to create something in Perl that is basically like the Unix
I would like to create a program in a linux/unix environment that runs from
How to find unix/linux system info like OS version, RAM, no. of processors, hard
Given an absolute or relative path (in a Unix-like system), I would like to
I would like my scripts works on Windows and UNIX system, so I want
I'd like to create a program that would connect my asp.net application to unix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.