開発したアプリなど一覧

WSL Ubuntu から Windows の exe を実行する

アフィリエイトリンクを含む場合があります

Windows Subsystem for Linux でインストールした Ubuntu 等の Linux からは Windows のアプリケーションを直接実行する事ができる。

例えばメモ帳を実行したければ以下のように notepad.exe と入力すれば良い。

$ notepad.exe

PATH が通っていればこのように exe 名を記述するだけで良い。必ず exe まで含めた名称を指定する必要がある。PATH が通ってなければ以下のように /mnt 以下にマウントされた Windows のドライブからフルパスで記述すると実行できる。

$ "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"

Windows では歴史的な事情により "Program Files" のようにスペースの入ったフォルダが多いが、上記のように "" で囲ってやれば問題なく利用できる。

PATH に関しては Windows 側で設定されたものは WSL でも利用できるようだ。現在自分の環境では以下のようになっているが、Windows のものは WSL 用に自動的に書き換わっているのがわかる。

$ echo $PATH /home/ryomatsu/.rbenv/shims /home/ryomatsu/.rbenv/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /mnt/c/Windows/System32 /mnt/c/Windows /mnt/c/Windows/System32/wbem /mnt/c/Windows/System32/WindowsPowerShell/v1.0 /mnt/c/Windows/System32/OpenSSH (Intel 関連のものは省略) /mnt/c/Program Files/Git/cmd /mnt/c/Users/ryomatsu/AppData/Local/Microsoft/WindowsApps /mnt/c/Python/Python3.5 /mnt/c/Python/Python3.5/Scripts

コマンドに引数を渡す場合は Windows のパスを指定する。例えば Windows にインストールした Python から Windows 上の py ファイルを実行する場合は以下のような感じ。

$ python.exe "C:\Dropbox\work\test\test.py" Hello world!

リダイレクトやパイプなどと組み合わせる事もできる。

$ ipconfig.exe | grep "IP" Windows IP Configuration IPv6 Address. . . . . . . . . . . : 204f:72:e89b:1:2345:6789:abcd:ef01 Temporary IPv6 Address. . . . . . : 24f0:72:e89b:1:2345:6789:abcd:ef00 Link-local IPv6 Address . . . . . : fe80::a05c:b30:4567:89ab%10 IPv4 Address. . . . . . . . . . . : 192.168.0.8 $ $ python.exe "C:\Dropbox\work\test\test.py" > test.py.output $ cat test.py.output Hello world!

Windows のアプリケーションは VoLFs(/mnt/ドライブレター 以外のパス) をサポートしないので注意が必要だ。

より詳しい情報は以下 Microsoft 公式ドキュメントを参照してほしい。

Windows interoperability with Linux | Microsoft Docs

Sponsored Link

コメント

タイトルとURLをコピーしました