1

I'm calling a powershell script from my C# application using:

System.Diagnostics.Process.Start("powershell.exe", " -executionpolicy unrestricted -file myscript.ps1");

Within this script is a call to Java (which relies on the CLASSPATH & PATH system variables). This is where the script fails and reports that:

java is not recognized as an internal command or external command

I believe this is because the system variables for PATH are not being used when I'm executing Powershell from C#. Any help ?

FYI, if I open Powershell manually and run the command it works correctly.

  • 1
    Why aren't you using the System.Management.Automation DLL instead of calling the PowerShell executable? –  Mar 27 '15 at 00:05
  • I have no idea why I'm not. Should I be doing this instead? I'm not new to dev work but I'm not familiar with best practices for Windows. Is this a better way of doing what I need? – MagicPepsiCan Mar 27 '15 at 00:14
  • check out [this question on running powershell from C#](http://stackoverflow.com/questions/527513/execute-powershell-script-from-c-sharp-with-commandline-arguments) or [these msdn documents](https://msdn.microsoft.com/en-us/library/dd182449(v=vs.85).aspx) for an example of what @TrevorSullivan is talking about – LinkBerest Mar 27 '15 at 01:20
  • ok thanks. In your opinion is this better than what I'm actually doing? – MagicPepsiCan Mar 27 '15 at 03:43
  • When trying to start the PowerShell object I get an InvalidProgramException. After some searching it seems this has happened to a few people but with no real resolution. Given that I can't go installing additional frameworks on our clients servers, what else can I do to fix this PATH issue? – MagicPepsiCan Mar 27 '15 at 05:35

0 Answers0