Powershell:pipe道input到通过调用运算符执行的命令

Powershell:pipe道input到通过调用运算符执行的命令,第1张

概述Powershell:pipe道input到通过调用运算符执行命令

我需要通过调用 *** 作符( & )dynamic执行batch file。 batch file需要参数,但是我还需要在stdin中传入一些input。 我认为这将工作:

$command = "somebatchfile.bat" "y" | & $command arg1 arg2

但是, "y"没有通过标准input。 如果我执行这样的batch file:

"y" | somebatchfile.bat arg1 arg2

然后一切按预期工作。 但是我不能硬编码path。

我怎样才能执行一个dynamic确定的batch file,它需要参数并通过一些标准input?

错误MSB3147:找不到所需的文件“setup.bin”发布到本地失败

什么会导致进程停止重新创build?

将winform放置在屏幕的左下angular

防止对象被分页(VirtualLock相当于)

如何使用C#访问iOS应用程序的documents文件夹

更新

为了重现这一点,我做了以下工作:

script.bat :

@echo off call script2.bat %*

script2.bat :

@echo off set /px="Enter: " echo foo %* %x%

Powershell会议 :

> $command = "./script.bat" > "yes!" | & $command whatever Enter: foo whatever yes!

所以它在这里按预期工作。 但是,当我用它与实际的batch file( androID.bat ,AndroID SDK的一部分),input不传递给java.exe。

这里是androID.bat的内容:

n@echo off rem copyright (C) 2007 The AndroID Open Source Project rem rem licensed under the Apache license,Version 2.0 (the "license"); rem you may not use this file except in compliance with the license. rem You may obtain a copy of the license at rem rem http://www.apache.org/licenses/liCENSE-2.0 rem rem Unless required by applicable law or agreed to in writing,software rem distributed under the license is distributed on an "AS IS" BASIS,rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implIEd. rem See the license for the specific language governing permissions and rem limitations under the license. rem Useful links: rem Command-line reference: rem http://technet.microsoft.com/en-us/library/bb490890.aspx rem don't modify the caller's environment setlocal enableextensions rem Set up prog to be the path of this script,including following symlinks,rem and set up progdir to be the fully-qualifIEd pathname of its directory. set prog=%~f0 rem Grab current directory before we change it set work_dir=%cd% rem Change current directory and drive to where the script is,to avoID rem issues with directorIEs containing whitespaces. cd /d %~dp0 rem Check we have a valID Java.exe in the path. set java_exe= call libfind_java.bat if not defined java_exe goto :EOF set jar_path=libsdkmanager.jar;libswtmenubar.jar rem Set SWT.Jar path based on current architecture (x86 or x86_64) for /f "delims=" %%a in ('"%java_exe%" -jar libarchquery.jar') do set swt_path=lib%%a :MkTempcopy rem copy androID.bat and its required libs to a temp dir. rem This avoIDs locking the tool dir in case the user is trying to update it. set tmp_dir=%TEMP%temp-androID-tool xcopy "%swt_path%" "%tmp_dir%%swt_path%" /I /E /C /G /R /Y /Q > nul copy /B /D /Y libcommon.jar "%tmp_dir%lib" > nul copy /B /D /Y libcommons-codec* "%tmp_dir%lib" > nul copy /B /D /Y libcommons-compress* "%tmp_dir%lib" > nul copy /B /D /Y libcommons-logging* "%tmp_dir%lib" > nul copy /B /D /Y libdvlib.jar "%tmp_dir%lib" > nul copy /B /D /Y libgson* "%tmp_dir%lib" > nul copy /B /D /Y libguava* "%tmp_dir%lib" > nul copy /B /D /Y libhttpclIEnt* "%tmp_dir%lib" > nul copy /B /D /Y libhttpcore* "%tmp_dir%lib" > nul copy /B /D /Y libhttpmime* "%tmp_dir%lib" > nul copy /B /D /Y liblayoutlib-API.jar "%tmp_dir%lib" > nul copy /B /D /Y liborg-eclipse-* "%tmp_dir%lib" > nul copy /B /D /Y libsdk* "%tmp_dir%lib" > nul copy /B /D /Y libswtmenubar.jar "%tmp_dir%lib" > nul rem jar_path and swt_path are relative to PWD so we don't need to adjust them,just change dirs. set tools_dir=%cd% cd /d "%tmp_dir%" :EndTempcopy rem The global ANDROID_SWT always overrIDe the SWT.Jar path if defined ANDROID_SWT set swt_path=%ANDROID_SWT% if exist "%swt_path%" goto SetPath echo ERROR: SWT folder '%swt_path%' does not exist. echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform. goto :EOF :SetPath rem Finally exec the java program and end here. REM set REMOTE_DEBUG=-XdeBUG -XrunjDWp:transport=dt_socket,server=y,suspend=y,address=8000 call "%java_exe% %rEMOTE_DEBUG%" "-Dcom.androID.sdkmanager.toolsdir=%tools_dir%" "-Dcom.androID.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%swt.jar" com.androID.sdkmanager.Main %* rem EOF

Java应用程序的执行正在促使许可证的接受,这就是为什么我要把"y"插入它的原因。 如果我直接pipe道它的作品,但如果我通过Powershell的呼叫运营商pipe道它不。

这工作:

"y" | androID.bat update sdk -u -a -t 38

这不:

$command = "androID.bat" "y" | & $command update sdk -u -a -t 38

任何人都可以启发我吗?

WTSquerySessioninformation返回一个不同的域名

检查windows窗体滚动条是否一直向下滚动?

为什么Microsoft.Build.Evaluation在64位PC上将$(Programfiles)评估为“c: program files”?

在windows中检测文件“copY” *** 作

如何devise一个单一的窗口多个视图的桌面与WPF?

我相信使用&来调用一个可执行文件需要参数是一个字符串数组,而不仅仅是一个字符串。 我认为PowerShell对于如何处理这个输入感到困惑。 所以,根据你的例子,像这样的东西应该正确地传递输入和参数:

$command = ".script1.bat" $x = "update sdk|-u|-a|-t 38" "myinput" | & $command $x.Split("|")

导致输出

Enter: foo "update sdk" -u -a "-t 38" myinput

总结

以上是内存溢出为你收集整理的Powershell:pipe道input到通过调用运算符执行的命令全部内容,希望文章能够帮你解决Powershell:pipe道input到通过调用运算符执行的命令所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1294369.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存