-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -OutputFile option #24
base: master
Are you sure you want to change the base?
Conversation
@@ -441,6 +445,11 @@ function Invoke-Sqlcmd2 { | |||
|
|||
} | |||
process { | |||
|
|||
if(-Not([string]::isNullOrEmpty($OutputFile)) -and $MessagesToOutput) { | |||
throw "Parameters OutputFile and MessagesToOutput are mutually exclusive" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most probably it can be achieved by using parameter sets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not used to parameter sets, but does this means that there should be 4 parameter sets for the function?
Con-Que
Con-Fil
Con-Que-Output
Con-Fil-Output
?
In that case, isn't it too heavy, just for adding one parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a look to the current param sets: [Parameter(ParameterSetName = 'Ins-Que'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's too much code addition and duplication (the param zone would double) for just adding one parameter while a 3 line code works well.
why the whole thing in the fist place ? PS output of any stream can be redirected to any given file pretty easily.... |
@niphlod Let's consider this simple case:
With |
What did you ever do @jeffchulg , I know it's been a while. Would appending |
Hi, personally, I modified Invoke-SqlCmd2 to do this:
|
Heard that. Glad it's working. Is the behavior any different than appending |
Well, it's a very old subject and I don't remember all the testing I made before, but, according to my comment :
This means you cannot instantly differenciate between a logging message, a verbose message from the PowerShell function and an actual resultset. The I'm not sure that a complete redirection as you propose would do that. |
I would think then all you would need is the I just tested this and it did work on the current build of the function. Invoke-sqlcmd2 localhost -Database db -Query "print 'hello world'
select 1" -Verbose 4> t.txt |
Could you try to raise an error and check that this error would be also thrown inside Powershell ? |
Yeah it does. I tested the below which does output to the file. All streams in powershell can be redirected like niphlod said above. Invoke-sqlcmd2 localhost -Database db -Query "print 'hello world'
raiserror(N'hello error' ,10 ,1 )
select 1" -Verbose 4> t.txt Here is the terminating error Invoke-sqlcmd2 localhost -Database db -Query "print 'hello world'
raiserror(N'hello fix this problem' ,16 ,1 )
select 1" -Verbose 4> t.txt Output of the error is below from Exception:
Line |
584 | [void]$da.fill($ds)
| ~~~~~~~~~~~~~~~~~~~
| Exception calling "Fill" with "1" argument(s): "hello fix this problem" |
Well, it's almost what I want, but here is the content I get with your test script:
With the OutputFile parameter, only "Hello world" would be written |
The source code on the Gallery is different than what is in this code base even though those version numbers are the same. Thus far I have been testing with the source code on this repo. Please try to pull the code directly from this code base. The code on github doesn't include the extra verbose output and would function more to your liking, I think. |
No description provided.