0

I've been struggling with this issue for some time now and it seems nobody on forums or google posted something like this, so I'll try to get some help here. I'm describing ec2 instances using vbs with multiple arguments and I'm using constant for NOT displaying command line window. Script works but instead of saving data into output file it saves it into a file that takes value of 'outFile' and adds some random numbers. Here is my command:

            'objShell.Run "%COMSPEC% /c aws ec2 describe-instances --region " & region + " --filters " & Filters + " --profile " & ProfileName + " --query " & Query + " --output " & oFormat + ">>" & outFile & WindowStyleStealth, false _

so before that code my outFile = "cmdresult.txt" and script writes data into cmdresult.txt546234895 - and I can't figure it out how to move around ">>" so it will append to that file. If I take out WindowStyleStealth, false and just leave:

... outFile _

then it works great but I do want to use the ability to hide command line window, so any help is greatly appreciated with this. VBscripting is not my forte so that might be another reason I can't figure this out but hopefully someone else had similar problem.

Thank you!

efg
  • 187
  • 13

1 Answers1

0

.Run takes 3 arguments, you pass 2:

... & oFormat + ">>" & outFile & WindowStyleStealth, false

This concatenates WindowStyleStealth to outFile. Change it to:

... & oFormat & ">>" & outFile, WindowStyleStealth, false

Update wrt comment:

Evidence:

>> region = "REGION"
>> Filters = "FILTERS"
>> ProfileName = "PROFILENAME"
>> Query = "QUERY"
>> oFormat = "FORMAT"
>> outFile = "cmdresult.txt"
>> sCmd = "%COMSPEC% /c aws ec2 describe-instances --region " & region & " --filters " & Filters & " --profile" & ProfileName & " --query " & Query & " --output " & oFormat & ">>" & outFile
>> WScript.Echo sCmd
>>
%COMSPEC% /c aws ec2 describe-instances --region REGION --filters FILTERS --profile PROFILENAME --query QUERY --output FORMAT>>cmdresult.txt
>>

Publish your code, if you still have problems.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • That still writes to a file cmdresult.txt536870912 instead of to cmdresult.txt. Any ideas on why this is happening? Thank you – efg Mar 24 '15 at 21:30
  • 1
    @kabucek - not if you replace the & before WindowStyleStealth with , - see Evidence (BTW: the concatenation operator is & in VBScript; mixing different styles of variable names is bad) – Ekkehard.Horner Mar 24 '15 at 21:54