6

I use the following command to launch new ConEmu powershell consoles.

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -new_console:n

I would like to pass an additional argument to specify a powershell script to run at startup of a new console. The following almost works but only prints the whole command and does not actually execute it:

ConEmu64.exe /config "shell" /dir "c:\" /cmd 'powershell -noexit -Command {Write-host "Hello world"}' -new_console:n

which produces:

Write-host Hello world
C:\>

while I am expecting:

Hello world
C:\>

2 Answers 2

4

Remove single quotas around your command. ConEmu executes intact string (command) which follows /cmd switch, with only exception - all -new_console... and -cur_console... are removed from this string before starting console.

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -noexit -Command Write-host "Hello world" -new_console:n
0

Ok Figured it out, its a quoting issue, but there is still some weirdness going on:

/config "shell" /dir "c:\" /cmd 'powershell -noexit -Command "& Write-host `"Hello world""' -new_console:n

That works and produces the expected:

Hello World
C:\>

but if you look carefully the quote at the end of "Hello World" is not escaped while the first one is. If I use the seemingly correct syntax:

/config "shell" /dir "c:\" /cmd 'powershell -noexit -Command "& Write-host `"Hello world`""' -new_console:n

I get

Hello world`
C:\>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .