Hey all! I am trying to open a browser window from CLI which works from a Linux terminal: xdg-open http://localhost:8080
But this code yields IOError "No such file or directory (os error 2)"
:
envPath <-
Env.var "PATH"
|> Task.onErr (\ VarNotFound -> crash "PATH env not found, really?")
|> await
res <-
Cmd.new "xdg-open"
|> Cmd.arg 'http://localhost:8080'
|> Cmd.env "PATH" envPath
|> Cmd.output
|> Task.onErr (\e -> crash (Inspect.toStr e))
|> await
I have also tried Cmd.new "/usr/bin/xdg-open"
, Cmd.new "sh -c" |> Cmd.arg "xdg-open http://localhost:8080"
and manually initializing PATH env var, but didn't get anywhere.
I am using --linker=legacy
Hmm, that code does work for me (on NixOS), can you share your OS and architecture?
Ubuntu 22.04.3 LTS, non-WSL, x86_64
Minimal example to reproduce for me, either with or without --linker=legacy:
app "hello"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.6.0/hJySbEhJV026DlVCHXGOZNOeoOl7468y9F9Buhj0J18.tar.br"
}
imports [pf.Task.{ Task, await }, pf.Cmd, pf.Env]
provides [main] to pf
url = "http://localhost:8080"
main =
envPath <- Env.var "PATH" |> Task.onErr (\ VarNotFound -> crash "PATH env not found, really?") |> await
{} <-
Cmd.new "xdg-open"
|> Cmd.arg url
|> Cmd.env "PATH" envPath
|> Cmd.output
|> Task.onErr (\e -> crash (Inspect.toStr e))
|> await
Task.ok {}
Thanks, I can take a look on my ubuntu vm tomorrow
That also works for me (on Ubuntu 22.04). To narrow this down, I would try:
roc build hello.roc
followed by strace ./hello
ls
command instead of xdg-open
and see if that runs without problems.I realized I was running the file in Ubuntu Docker container (same version as the host machine). Directly on host the code works fine. I can keep developing in container and testing on host, but eventually I'd like to be able run my CLI app within the container, too.
Here is the strace when running in the container:
open("/proc/self/exe", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=S_IFREG|0755, st_size=2759264, ...}) = 0
mmap(NULL, 2759264, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fb4b2e00000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b3449000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b3448000
munmap(0x7fb4b3449000, 4096) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b3446000
munmap(0x7fb4b3448000, 4096) = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b3442000
munmap(0x7fb4b3446000, 8192) = 0
mmap(NULL, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b343b000
munmap(0x7fb4b3442000, 16384) = 0
mmap(NULL, 53248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b31f3000
munmap(0x7fb4b343b000, 28672) = 0
mmap(NULL, 102400, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4b31da000
munmap(0x7fb4b31f3000, 53248) = 0
stat("/usr/lib/debug", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/debug/.build-id/c9/d2cee6f567f1cc0aacc6fa91c163c14279364b.debug", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/proc/self/exe.dwp", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
/usr/lib/debug/.build-id/
was indeed missing inside the container, so I ran
sudo apt-get update && sudo apt-get install libc6-dbg
in the container and recompiled the Roc program but still getting the same strace. The issue persists with --optimize flag, too.
Strange, I'm investigating...
Can you share your Dockerfile?
https://github.com/feldera/feldera/blob/main/.devcontainer/Dockerfile
I am using a nightly build of Roc, not compiling from source btw
It doesn't really make sense to run xdg-open from inside docker right?
Oh, crap. I just realized it probably doesn't :sweat_smile: And thus xdg-utils are not even installed in a Docker container. Sorry for leading you down the wrong path!
Karakatiza has marked this topic as resolved.
To sum up: the original code is valid and works in an environment with a desktop subsystem (and with xdg-utils) installed.
Last updated: Jul 06 2025 at 12:14 UTC