Zulip Chat Archive
Stream: new members
Topic: Understanding calling command line functions
Peter Tupoiu (Aug 11 2024 at 20:29):
I'm trying to use a command line function and I'm getting a funny error:
def main : IO Unit := do
-- let test <- IO.FS.readFile "lakefile.lean"
-- IO.println test
IO.println "HELLO!"
let files <- IO.Process.run {cmd := "ls"}
IO.println files
And when I run lean .\Main.lean --run
I get:
HELLO!
uncaught exception: no such file or directory (error code: 2)
Peter Tupoiu (Aug 11 2024 at 20:30):
I was expecting it to just print the results of ls
. Looking at IO.lean
I expect that means it's unable to detect my current working directory?
(the IO.FS.readFile
works fine, by the way)
Sebastian Ullrich (Aug 12 2024 at 06:00):
I don't think that's a standard Windows executable, are you sure it's in your PATH?
Sebastian Ullrich (Aug 12 2024 at 06:01):
And the .exe may be mandatory
Peter Tupoiu (Aug 12 2024 at 06:10):
Sebastian Ullrich said:
I don't think that's a standard Windows executable, are you sure it's in your PATH?
Hi Sebastian,
I am talking with Nix (not sure of their real name) on the FP discord server about this issue, and apparently there was a fix recently (or at least one to a related issue) in 4.10. The same happened with “dir” and “echo hello” as the commands.
(edit: Apparently ls is a powershell command)
Richard Copley (Aug 12 2024 at 15:45):
dir
and echo
aren't executables either, on Windows, as standard. They are handled by the interpreter cmd.exe
(or by Powershell -- maybe they are provided separately as applets, but I don't know much about that). You could try executing cmd.exe /c "dir /b"
.
Peter Tupoiu (Aug 12 2024 at 17:38):
Richard Copley said:
dir
andecho
aren't executables either, on Windows, as standard. They are handled by the interpretercmd.exe
(or by Powershell -- maybe they are provided separately as applets, but I don't know much about that). You could try executingcmd.exe /c "dir /b"
.
Aha - this worked. Little bit arcane, but maybe that is just the price I pay for windows.
edit:
Final code
def main : IO Unit := do
IO.println "HELLO!"
let files <- IO.Process.run {cmd := "powershell.exe /c ls"}
IO.println files
Last updated: May 02 2025 at 03:31 UTC