如何让 ConEmu 在启动时执行 powershell 脚本?

Mik*_*enn 6 powershell conemu

我使用以下命令启动新的 ConEmu powershell 控制台。

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -new_console:n
Run Code Online (Sandbox Code Playgroud)

我想传递一个额外的参数来指定在新控制台启动时运行的 powershell 脚本。以下几乎可以工作,但只打印整个命令而不实际执行它:

ConEmu64.exe /config "shell" /dir "c:\" /cmd 'powershell -noexit -Command {Write-host "Hello world"}' -new_console:n
Run Code Online (Sandbox Code Playgroud)

它产生:

Write-host Hello world
C:\>
Run Code Online (Sandbox Code Playgroud)

虽然我期待:

Hello world
C:\>
Run Code Online (Sandbox Code Playgroud)

Max*_*mus 4

删除命令周围的单个配额。ConEmu 执行 switch 后面的完整字符串(命令)/cmd,只有一个例外 - 在启动控制台之前,所有-new_console...-cur_console...都从该字符串中删除。

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -noexit -Command Write-host "Hello world" -new_console:n
Run Code Online (Sandbox Code Playgroud)