Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add -WhatIf switch to Start-Process cmdlet#4735

Merged
iSazonov merged 7 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
sarithsutha:start-process-enhancementssarithsutha/PowerShell:start-process-enhancementsCopy head branch name to clipboard
Sep 8, 2017
Merged

Add -WhatIf switch to Start-Process cmdlet#4735
iSazonov merged 7 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
sarithsutha:start-process-enhancementssarithsutha/PowerShell:start-process-enhancementsCopy head branch name to clipboard

Conversation

@sarithsutha

Copy link
Copy Markdown
Contributor

Closes #4702

Add -WhatIf switch to Start-Process cmdlet

@msftclas

msftclas commented Sep 1, 2017

Copy link
Copy Markdown

@sarithsutha,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot


It "Should be able to use the whatif switch without error" {
{ Start-Process $pingCommand -ArgumentList $pingParam -WhatIf } | Should Not Throw
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a test that would normally perform an action and ensure that -WhatIf prevented the action?
For example, have a Start-Process command to write a string to a file and then test to ensure the file was not written to with -WhatIf is supplied.

@bergmeister bergmeister Sep 3, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also a test that using the -PassThru switch, no object gets returned (which is also a good additional test that the command was not executed)?

It "returns null when using -WhatIf switch with `PassThru`" {
     { Start-Process $pingCommand -ArgumentList $pingParam -PassThru -WhatIf } | Should Be $null
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion @bergmeister . I've added the test that you described.

@sarithsutha

Copy link
Copy Markdown
Contributor Author

Thanks for your suggestion @markekraus . I've added that test.


It "Should be able to use the whatif switch without error" {
{ Start-Process $pingCommand -ArgumentList $pingParam -WhatIf } | Should Not Throw
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test does not need - next do the check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I did not get which - were you referring to.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant next It block.

It "Should be able to use the whatif switch without performing the actual action" {
$pingOutput = Join-Path $TestDrive "pingOutput.txt"
Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf
Test-Path $pingOutput | Should Be $false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

$pingOutput | Should Not Exist 

</data>
<data name="ProcessStartInfo" xml:space="preserve">
<value>{0} {1}</value>
</data>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We re-use ProcessNameForConfirmation in Stop-Process and Debug-Process so I believe we can use the same in Start-process.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original request was to output the exact command being executed. By re-using the ProcessNameForConfirmation, the format of the output will be changed slightly, the arguments would appear in the parentheses. i.e. C:\WINDOWS\system32\PING.EXE (-n 2 localhost) instead of C:\WINDOWS\system32\PING.EXE -n 2 localhost.
If that is acceptable, I'm happy to make the change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarify.
Closed.


It "Should be able to use the whatif switch without performing the actual action" {
$pingOutput = Join-Path $TestDrive "pingOutput.txt"
Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf

@iSazonov iSazonov Sep 5, 2017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove next It and do the check here.

It "Should be able to use the -WhatIf switch without performing the actual action" {
$pingOutput = Join-Path $TestDrive "pingOutput.txt"
Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf
{ Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf} | Should Not Throw

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe -ErrorAction Stop is required or it will never actually throw.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @markekraus for pointing this out. Not sure how I missed it.

@iSazonov iSazonov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor failed on other tests so the PR LGTM with one minor comment..

@sarithsutha

Copy link
Copy Markdown
Contributor Author

Thanks @iSazonov for reviewing and approving my changes. The minor comment is now incorporated.

@markekraus markekraus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iSazonov

iSazonov commented Sep 6, 2017

Copy link
Copy Markdown
Collaborator

@daxian-dbw Could you please review and approve?

startInfo.WindowStyle = _windowstyle;
}

string targetMessage = StringUtil.Format(ProcessResources.ProcessStartInfo, startInfo.FileName, startInfo.Arguments.Trim());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resource string id ProcessStartInfo should be changed to StartProcessTarget.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxian-dbw Renamed the resource string as suggested.

@daxian-dbw daxian-dbw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarithsutha Thanks!

@iSazonov iSazonov merged commit f4b075c into PowerShell:master Sep 8, 2017
@iSazonov

iSazonov commented Sep 8, 2017

Copy link
Copy Markdown
Collaborator

@sarithsutha Thanks for your contribution!

@sarithsutha sarithsutha deleted the start-process-enhancements branch September 8, 2017 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.