Returns the fully qualified path to the file if it is fully-qualified, exists in the current directory, or in the environment path, otherwise generates a FileNotFoundException exception.
Syntax
Visual Basic (Declaration) | |
---|
Public Shared Function FindFullPath( _
ByVal location As String _
) As String |
Parameters
- location
Exceptions
Example
Library/Library.Test/TestProcessRunner.cs
C# | Copy Code |
---|
string tempfile = Path.GetTempFileName();
try
{
Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"));
ProcessRunner runner = new ProcessRunner("cmd.exe");
Assert.IsFalse(runner.IsRunning);
runner.Kill(); // always safe to call
runner.Start("/K", "ECHO Hello > " + tempfile);
Assert.IsTrue(runner.IsRunning);
try //make sure we can't start twice.
{
runner.Start("/C", "ECHO", "HELO");
Assert.Fail();
}
catch (InvalidOperationException)
{ }
Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false));
runner.Kill();
string output = File.ReadAllText(tempfile).Trim();
Assert.AreEqual("Hello", output);
}
finally
{ File.Delete(tempfile); } |
VB.NET | Copy Code |
---|
Dim tempfile As String = Path.GetTempFileName()
Try
Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"))
Dim runner As New ProcessRunner("cmd.exe")
Assert.IsFalse(runner.IsRunning)
runner.Kill()
' always safe to call
runner.Start("/K", "ECHO Hello > " + tempfile)
Assert.IsTrue(runner.IsRunning)
Try
'make sure we can't start twice.
runner.Start("/C", "ECHO", "HELO")
Assert.Fail()
Catch generatedExceptionName As InvalidOperationException
End Try
Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), False))
runner.Kill()
Dim output As String = File.ReadAllText(tempfile).Trim()
Assert.AreEqual("Hello", output)
Finally
File.Delete(tempfile)
End Try |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also