Run(`start`) doesn't work

I used my python program to open webpage automatically.

import os
os.system("start https://discourse.julialang.org/")

But julia version can’t, even git commands are working. Any help?

PS C:\Users\rmsms> start https://discourse.julialang.org/
PS C:\Users\rmsms> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> run(`start https://discourse.julialang.org/`)
ERROR: IOError: could not spawn `start https://discourse.julialang.org/`: no such file or directory (ENOENT)

Env

  • julia 1.10
  • windows 11
    • window terminal 1.18.3181.0

I am guessing that start is not a program you have on your computer,
but rather a powershell intrinstic.

Julia’s run command doesn’t run inside any shell.

Try running your browser directly,
e.g.

run(`firefox https://discourse.julialang.org/`)
4 Likes

It’s actually, for default browser:

run(`xdg-open https://discourse.julialang.org/`)

which for me was firefox, I hadn’t set it to edge, so I started it unwantingly…

The correct way is platfoem-specific, most likely doesn’t work on Windows (does on macOS?), so arguable could be in Base, or already in a package?

I see now you’re on Windows:

There’s also another option…:

See package DefaultApplication.jl for a platform-independent solution.

3 Likes

@tpapp, I see one bug, sort of, there:

@static if Sys.isapple()

This means the package works, usually (and makes compiled code smaller), but I believe if you cross-compile on e.g. macOS, for Windows, then you get the wrong macOS behavior on Windows… (am I wrong, or if not is @static a sort of code-smell for AppBundler/PackageCompiler?). Since the code is basically 80 lines, and not speed- nor compiled-code-size-critical, do without this?

I sort of recalled this package, and it’s not just to start web browsers, all sort of files, e.g. JPEG, in some viewer, or text files in an editor. Given how useful, and that people are likely to hard-code platform-specific behavior, e.g. for Windows, use notepad…, people should use this solution, and I could argue adding it to Base. I know it doesn’t strictly need to be there, but for discoverability would be good or at least in Julia’s docs.