nek*_*uuu 5 windows windows-subsystem-for-linux
我想在 Windows上的 Ubuntu(即 WSL)上的 bash 中使用 Windowsstart命令。但是,我不能通过简单地输入来使用它start:
nek@NEK:/mnt/c/Users/Nek$ start test.txt
Command 'start' is available in '/sbin/start'
The command could not be located because '/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with your user account.
start: command not found
Run Code Online (Sandbox Code Playgroud)
我注意到这start.exe可能不存在。
C:\Users\Nek>where start
INFO: Could not find files for the given pattern(s).
Run Code Online (Sandbox Code Playgroud)
是start内置命令吗?我们可以start在 bash 中使用吗?
.exe在 bash 上执行文件是旧版本。我应该更新 Windows 版本 >= 14951,然后按照答案进行操作。)Dav*_*ill 11
是的。
内部命令
Windows CMD shell CMD.exe 包含许多“内部”命令,其他“外部”命令也作为单独的可执行文件提供。外部命令一般存放在 C:\WINDOWS\System32 文件夹中,该文件夹是系统 PATH 的一部分。
这种安排意味着无论您当前的目录是什么,内部和外部命令始终可用。
ASSOC、BREAK、CALL、CD/CHDIR、CLS、COLOR、COPY、DATE、DIR、DIR、DPATH、ECHO、ENDLOCAL、ERASE、EXIT、FOR、FTYPE、GOTO、IF、KEYS、MD/MKDIR、MKLINK(vista 和以上)、移动、路径、暂停、弹出、提示、推送、REM、REN/RENAME、RD/RMDIR、SET、SETLOCAL、SHIFT、START、TIME、TITLE、TYPE、VER、VERIFY、VOL
源语法内部
是的。启动命令外壳并运行 start 命令。
例子:
cmd.exe /c start "" test.txt
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,请按如下方式指定完整路径:
/mnt/c/Windows/system32/cmd.exe /c start "" test.txt
Run Code Online (Sandbox Code Playgroud)
在其他答案中,cmd.exe建议。但是,命令提示符不支持 UNC 路径。WSL2 中的 Linux 文件系统在 Windows 中表示为 UNC 路径。
在这种情况下,更好的选择是PowerShell。借用Alex G的函数,将其重写为:
function start {
abspath=$(readlink -f "$1");
wpath=$(/bin/wslpath -w "$abspath");
powershell.exe -Command Start-Process "$wpath"
}
Run Code Online (Sandbox Code Playgroud)
[interop] appendWindowsPath = false如果您通过添加to禁用了 Windows PATH 添加/etc/wsl.conf,则使用通过以下方式获取的绝对路径where powershell.exe:
function start {
abspath=$(readlink -f "$1");
wpath=$(/bin/wslpath -w "$abspath");
/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0//powershell.exe -Command Start-Process "$wpath"
}
Run Code Online (Sandbox Code Playgroud)
将其添加到您的中.bashrc,以确保您在每个会话中都有它。
用法:
start .- 在 Windows 文件资源管理器中打开当前目录。start /any/linux/path- 将 Linux 目录作为 UNC 路径打开。start /mnt/c/any/windows/path- 以常规路径打开 Windows 文件夹。start- 强制 PowerShell 命令提示您输入路径。输入一个,例如.或 Windows/UNC 路径(Linux 路径在此处不起作用)或按Ctrl-C取消。
| 归档时间: |
|
| 查看次数: |
21062 次 |
| 最近记录: |