简体   繁体   English

Powershell命令输入CMD时不起作用

[英]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.我试图从 CMD(控制面板中的时间和日期)开始一个快捷方式,但它不起作用,所以我尝试在 Powershell 中做同样的事情。

In Powershell I wrote this command and it worked first try.在 Powershell 中,我编写了这个命令,它第一次尝试就起作用了。

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.但由于某种原因,如果我尝试在 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其中括号中的命令是从 Powershell 复制而来的

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.系统 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.出于某种原因,CMD 会将单词časzástupce之间的空格更改为不同的空格。

To be exact these spaces čas – zástupce确切地说,这些空间čas – zástupce

Powershell's spaces looks like this in binary (dash included) 00100000 11100010 10000000 10010011 00100000 Powershell 的空格在二进制中看起来像这样(包括破折号) 00100000 11100010 10000000 10010011 00100000

When I copy the command pasted in CMD it looks like this (dash included) 00100000 00101101 00100000当我复制粘贴在 CMD 中的命令时,它看起来像这样(包括破折号) 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 . startStart-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.它们在控制台上有助于减少打字,但它们应该是 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:如果您认为 cmd.exe 正在更改空格,请将Start-Process命令放入 doit.ps1 文件并调用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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