Home > Software engineering >  Using |findstr in a & execution statement
Using |findstr in a & execution statement

Time:12-02

I have an application which allows command line parameters to be parsed. I filter out some lines with findstr.exe. The following command does exactly what I want from the command line:

"c:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe" -id=userid -password=password -tcpserveraddress=myserver.domain.com -tcpport=1500 -console|findstr /v /c:ANR0403I /c:ANR0406I /c:ANR0950I /c:ANR1639I /c:ANR0951I /c:ANR3692W /c:ANR8592I /c:ANE49

Now I try to create a Powershell script and parse the parameters to the command. The following code works when I use it without filtering with findstr:

param(
  [string]$id,
  [string]$password,
  [string]$tcpserveraddress,
  [string]$tcpport
)
[Array]$parameters = "-id=$id","-password=$password","-tcpserveraddress=$tcpserveraddress","-tcpport=$tcpport","-console"
& 'c:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe' $parameters

I don't know how I should include the |findstr /v /c:ANR0403I /c:ANR0406I /c:ANR0950I /c:ANR1639I /c:ANR0951I /c:ANR3692W /c:ANR8592I /c:ANE49 into my command. Can anybody help me out here please? Thank you very much for your help in advance!

Kind regards, Eric

CodePudding user response:

Thanks to the suggestion of iRon, I replaced findstr with the following line:

& 'c:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe' $parameters | Select-String -Pattern 'ANR0403I','ANR0406I','ANR0950I','ANR1639I','ANR0951I','ANR3692W','ANR8592I','ANE49' -NotMatch -SimpleMatch

And this works as charm. Thanks @iRon!

Kind regards, Eric van Loon

  • Related