简体   繁体   English

"从 cmd 窗口使用管道符号将值传递给 powershell Start-Process 命令"

[英]Pass value using pipe symbol to a powershell Start-Process command, from cmd window

I have a batch script like below.我有一个如下所示的批处理脚本。 I want to call this script from a terminal window (cmd)<\/code> , by running it using powershell<\/code> Start-Process<\/code> command (Doing this in Azure ARM Template)<\/em> .我想从终端窗口(cmd)<\/code>调用此脚本,方法是使用powershell<\/code> Start-Process<\/code>命令(在 Azure ARM 模板中执行此<\/em>操作)运行它。 I want to pass the INPUT<\/code> value while calling the script, probably by using a pipe symbol.我想在调用脚本时传递INPUT<\/code>值,可能是使用管道符号。

Not able to pass the INPUT<\/code> value through pipe symbol to a Start-Process<\/code> command.无法通过管道符号将INPUT<\/code>值传递给Start-Process<\/code>命令。 Am I missing something?我错过了什么吗? How can I achieve this (without any modifications to this batch file)<\/em> ?我怎样才能实现这一点(无需对此批处理文件进行任何修改)<\/em> ?

@echo off
SETLOCAL EnableDelayedExpansion

set INPUT=
set /P INPUT=Type yes or no: %=%

echo[
echo actually typed %INPUT%

IF "%INPUT%"=="n" goto :CLICKEDNO
IF "%INPUT%"=="N" goto :CLICKEDNO
IF "%INPUT%"=="NO" goto :CLICKEDNO
IF "%INPUT%"=="no" goto :CLICKEDNO
IF "%INPUT%"=="No" goto :CLICKEDNO
IF "%INPUT%"=="yes" goto :CLICKEDYES
IF "%INPUT%"=="Yes" goto :CLICKEDYES
IF "%INPUT%"=="Y" goto :CLICKEDYES
IF "%INPUT%"=="y" goto :CLICKEDYES

:CLICKEDYES
echo Typed yes
goto :eof

:CLICKEDNO
echo Typed no
goto :eof

echo end of file

You do not need to do a match for each case.您不需要为每种情况进行匹配。 use if \/i<\/code> to match case insensitive, we also need to use %1<\/code> to specify :使用if \/i<\/code>来匹配不区分大小写,我们还需要使用%1<\/code>来指定:

@echo off

echo Type Yes/no & set /P "in=%1"

if /i "%in%" == "n" goto :no
if /i "%in%" == "no" goto :no
if /i "%in%" == "y" goto :yes
if /i "%in%" == "yes" goto :yes

:yes
echo Typed yes
goto :eof

:no
echo Typed no
goto :eof

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

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