Run powershell script

Aug 31, 2010 at 2:29 PM

Hi,

I'm trying to run a powershell script through White and NUnit. The powershell script when it runs pops up a file open dialog box for you to choose a file that it will process.
I'm currently doing something like the following:

string _strPowershell = @"C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe";
Process.Start(_strPowershell, string.Format("-noexit &'{0}'", _strPowershellScript)); 

This will run the powershell script and open the file dialog box. But now i need access to the dialog box so that I can put in the file that it needs.
I have been using the following before when it came to handling file open dialog boxes but  the application varable is null here simply because I'm not using Application.Launch.

List<Window> windows = application.GetWindows();
Window fileOpen = windows.Where(p => p.Title == "Open").First();
TextBox FilePathTextbox = fileOpen.Get<TextBox>("File name:");
FilePathTextbox.SetValue(Path.Combine(_strFileLocation, _strFileName));
fileOpen.Get<Button>("Open").Click();



Any ideas on how to get this working, say using Application.Launch?

Sep 1, 2010 at 12:27 PM

Or could Application.Launch() be extended to take an optional argument argument?

Sep 1, 2010 at 12:47 PM
Edited Sep 1, 2010 at 12:48 PM

Hi,

you can try this one:

 

m_Application = White.Core.Application.AttachOrLaunch(new ProcessStartInfo(_strPowershell));

 

hope it works for you.

 

Regards

Angel

Sep 3, 2010 at 3:57 PM

Excellent. That worked a treat. Thanks. I did the following:

Application application = Application.AttachOrLaunch(new ProcessStartInfo(_strPowershell, string.Format("-noexit &'{0}'", _strScript)));

I now have a new issue you might know how to solve.
The powershell script takes about 5 minutes to run. When it finishes it doesn't close the command promt window but it does say something like "Run Successfully Completed" followed by the prompt.
Is there any way of reading the text in the command prompt window to recognise when that script has finished so that I know when to move on with the next White commands? This would obviously be attempted to be read inside a while loop with a sleep timer.

Thanks

Sep 6, 2010 at 10:57 AM
Edited Sep 6, 2010 at 10:58 AM

Hi,

i am not sure if you can read from command window, I think that is not possible. You can try to pop up modal window when your script is ready and than close it.

 

Regards

Angel