Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Windows shell commands in Julia

Tags:

shell

julia

Supposedly in Julia I can run shell commands by first hitting ;. But I'm having no luck on my Windows 7 machine. Here's an example where I first run dir in the shell, and then try to do the same in Julia:

C:\Users\Public>dir
 Volume in drive C is OS
 Volume Serial Number is A4A2-4168

 Directory of C:\Users\Public

01/30/2016  03:31 AM    <DIR>          .
01/30/2016  03:31 AM    <DIR>          ..
07/13/2009  09:08 PM    <DIR>          Documents
07/13/2009  08:54 PM    <DIR>          Downloads
01/02/2017  10:56 AM    <DIR>          Music
01/16/2016  02:53 PM           262,144 NTUSER.DAT
07/13/2009  08:54 PM    <DIR>          Pictures
11/20/2010  11:16 PM    <DIR>          Recorded TV
01/05/2016  06:06 AM    <DIR>          Roaming
07/13/2009  08:54 PM    <DIR>          Videos
               1 File(s)        262,144 bytes
               9 Dir(s)  850,167,861,248 bytes free

C:\Users\Public>julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.0 (2016-09-19 18:14 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-w64-mingw32

shell> dir
ERROR: could not spawn `dir`: no such file or directory (ENOENT)
 in _jl_spawn(::String, ::Array{String,1}, ::Ptr{Void}, ::Base.Process, ::RawFD, ::RawFD, ::RawFD) at .\process.jl:3
21
 in #414 at .\process.jl:478 [inlined]
 in setup_stdio(::Base.##414#415{Cmd,Ptr{Void},Base.Process}, ::Tuple{RawFD,RawFD,RawFD}) at .\process.jl:466
 in #spawn#413(::Nullable{Base.ProcessChain}, ::Function, ::Cmd, ::Tuple{RawFD,RawFD,RawFD}, ::Bool, ::Bool) at .\pr
ocess.jl:477
 in run(::Cmd) at .\process.jl:591
 in repl_cmd(::Cmd, ::Base.Terminals.TTYTerminal) at .\client.jl:91

julia>

I've tried other commands, and cd works, but cls does not. What's gone wrong here?

like image 209
Yly Avatar asked Jan 14 '17 00:01

Yly


People also ask

How do I run Julia command line?

You can run a Julia file (via Ctrl+F5, which will run whatever Julia file you have open and active), execute Julia commands via the REPL, or even execute a specific block of code from a file you have open.

What is Julia command?

Julia is a programming language that is freely available. Launch Binder. We can use Julia without installation by clicking the "launch Binder" badge. The notebook CalculusWithJulia. ipynb is a blank notebook except for the command to load the CalculusWithJulia package.

What is Julia REPL?

Julia comes with a full-featured interactive command-line REPL (read-eval-print loop) built into the julia executable. In addition to allowing quick and easy evaluation of Julia statements, it has a searchable history, tab-completion, many helpful keybindings, and dedicated help and shell modes.


2 Answers

This works:

shell>cmd /c dir
like image 58
Yly Avatar answered Oct 21 '22 13:10

Yly


The problem is that lots of "commands" in Windows are builtins rather than programs. If someone wanted to implement special handling of all the cmd builtins on Windows, a PR would be welcomed.

like image 42
StefanKarpinski Avatar answered Oct 21 '22 13:10

StefanKarpinski