简体   繁体   中英

Powershell command does not work when inputed into CMD

I was trying to start a shortcut from CMD (Time and date from control panel) which did not work, so I tried to do the same in Powershell where it did.

In Powershell I wrote this command and it worked first try.

cd 'C:\Users\JakubLL\Desktop\Zástupci!' ; start '.\Datum a čas – zástupce.lnk'

But for some reasone this is not the case if I try to run the exact same command in CMD.

When I try this command:

powershell -command "& {cd 'C:\Users\JakubLL\Desktop\Zástupci!' ; start '.\Datum a čas - zástupce.lnk'}"

where the command inbetween brackets is copied from Powershell it self

the return is this:

start : This command cannot be run due to the error: Systém nemůže nalézt uvedený soubor.
At line:1 char:46
+ ... rs\JakubLL\Desktop\Zástupci!' ; start '.\Datum a čas - zástupce.lnk'}
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Systém nemůže nalézt uvedený soubor. translates to: System cannot find the file specified.

For some reasone CMD wil change the spaces between the word čas and zástupce to different ones.

To be exact these spaces čas – zástupce

Powershell's spaces looks like this in binary (dash included) 00100000 11100010 10000000 10010011 00100000

When I copy the command pasted in CMD it looks like this (dash included) 00100000 00101101 00100000

Can please someone help me with this. And also sorry if my english is not the best.

EDIT: It is not the spaces but the dash it self!

start is an alias for Start-Process . Aliases should not be put into code. They are helpful at a console for less typing, but that is as far as they should go.

powershell -NoLogo -NoProfile -Command ^
    "Start-Process -WorkingDirectory 'C:\Users\JakubLL\Desktop\Zástupci!' `" ^
    "    -FilePath '.\Datum a čas – zástupce.lnk'"

If you believe cmd.exe is changing the spaces, put the Start-Process command into a doit.ps1 file and invoke it with:

powershell -NoLogo -NoProfile -File '.\doit.ps1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM