从Powershell的调用程序瓦特/很长,变量参数列表? [英] Call a program from Powershell w/ very long, variable argument list?

查看:243
本文介绍了从Powershell的调用程序瓦特/很长,变量参数列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为一系列的批处理文件转换为PowerShell脚本。我想运行中存在的目录中的源文件编译器,递归。编译器需要的参数一长串。美中不足的是,我要的参数是可变的,需要,我可以改变它们。这是从批处理文件中典型的呼叫(简化了可读性和长度):

I am currently trying to convert a series of batch files to powershell scripts. I would like to run a compiler for the source files that exist in a directory, recursively. The compiler requires a long list of arguments. The catch is, I want the arguments to be variable so I can change them as needed. This is a typical call from the batch file (simplified for readability and length):

C:\\ PICC编译器\\ picc18.exe--pass1
  C:\\ Src的文件\\ somefile.c
  -IC:\\包含文件-IC:\\头
  文件-P
  --runtime =默认状态下,+清晰,+初始化,-keep,+下载+ stackwarn,-config,+ CLIB,-plib
  --opt =默认状态下,+ ASM, - 速度,+空格,9 --warn = 0 = --debugger realice -Blarge - 双= 24 --cp = 16 -g --asmlist--errformat =错误[ %N]%F;%L%C
  %S--msgformat =咨询[%N]%S--OBJDIR =C:\\内置文件
  --warnformat =警告[%N]%F;%1%C%的

"C:\PICC Compilers\picc18.exe" --pass1 "C:\Src Files\somefile.c" "-IC:\Include Files" "-IC:\Header Files" -P --runtime=default,+clear,+init,-keep,+download,+stackwarn,-config,+clib,-plib --opt=default,+asm,-speed,+space,9 --warn=0 --debugger=realice -Blarge --double=24 --cp=16 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" --OBJDIR="C:\Built Files" "--warnformat=Warning [%n] %f; %l.%c %s"

包含在批处理文件时,此命令执行罚款,但是当我复制并粘贴命令到PowerShell的我开始越来越错误。这只是我第二天使用PowerShell的工作,但我已经在过去的.NET开发。我设法凑了以下尝试:

This command executes fine when included in a batch file, but I start getting errors when I copy and paste the command into powershell. This is only my second day working with powershell, but I have developed with .NET in the past. I have managed to scrape together the following attempt:

$srcFiles = Get-ChildItem . -Recurse -Include "*.c"
    $srcFiles | % {
    $argList = "--pass1 " + $_.FullName;
    $argList += "-IC:\Include Files -IC:\Header Files -P --runtime=default,+clear,+init,-keep,+download,+stackwarn,-config,+clib,-plib --opt=default,+asm,-speed,+space,9 --warn=0 --debugger=realice -Blarge --double=24 --cp=16 -g --asmlist '--errformat=Error   [%n] %f; %l.%c %s' '--msgformat=Advisory[%n] %s' '--warnformat=Warning [%n] %f; %l.%c %s"
    $argList += "--OBJDIR=" + $_.DirectoryName;
    &"C:\PICC Compilers\picc18.exe" $argList }

我知道,我可能有上述code多的问题,即如何来传递参数,以及如何我处理的参数列表引号。因为不正确的是,它应该说明了什么,我想要的目的。从哪里开始有什么建议?

I know that I probably have multiple issues with the above code, namely how to pass arguments and how I am dealing with the quotes in the argument list. Incorrect as it is, it should illustrate what I am trying to achieve. Any suggestions on where to start?

推荐答案

从调用PowerShell命令行应用程序可能是真正棘手。几个星期前@Jaykul rel=\"nofollow\">的写了精彩的博客贴子的问题在那里,他介绍了陷阱,人们将在此情况下见面。还有当然是解决太;)

Calling command line applications from PowerShell might be really tricky. Several weeks ago @Jaykul wrote great blog post The problem with calling legacy/native apps from PowerShell where he describes gotchas which people will meet in this situations. And there is of course solution too ;)

编辑 - 正确的网址

这篇文章是没有更多的可用,所以它只是可以看到,通过web.archive.org - 见<一href=\"http://web.archive.org/web/20110527182556/http://huddledmasses.org/the-problem-with-calling-legacy-or-native-apps-from-powershell/\"相对=nofollow>缓存文章

The article is no more available, so it's only possible to see that through web.archive.org - see cached article

这篇关于从Powershell的调用程序瓦特/很长,变量参数列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆