powershell - 制作批处理文件时遇到问题
问题描述
我正在尝试制作一个 bacth 文件,该文件将制作第二个 bacth 文件并将其内容设置为:
电源外壳关机 /s /f /t 0
我尝试使用的命令是 powershell set-content "shutdown.bat" "powershell shutdown /s /f /t 0"
当我运行它时,我得到了这个:
Set-Content : A positional parameter cannot be found that accepts argument 'shutdown'.
At line:1 char:1
+ set-content -Path shutdown.bat -Value powershell shutdown /s /f /t 0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
解决方案
这个 ...
powershell shutdown /s /f /t 0
... 不是使用 Powershell 运行外部命令行工具或其他程序的方式。要运行外部工具,这是一个有据可查/谈论的事情......
...以及相当日常的活动。
在做你想做的事情时,正确的引用和参数终止是一项要求。
所以,像这样的东西...
powershell -ArgumentList '-Command &{ shutdown /s /f /t 0 }'
推荐阅读
- c++ - 类型别名和类似类型
- makefile - 使用 make 进行部分并行和串行编译
- excel - MONTH/YEAR 条件下的 SUM 值
- python - 在 python 中用 exec(open(file).read()) 杀死程序运行
- r - 计算给定栅格堆栈的阈值以上连续值的最大长度
- excel - Excel VBA SQL 多个where条件
- optimization - 高维规划问题的启发式/求解器
- .htaccess - 奇怪的 URL RewriteRule 行为
- java - org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误
- mysql - Docker - PHP/MySQL - php_network_getaddresses:getaddrinfo 失败:名称或服务未知