batch file execution in c#

后端 未结 4 749
南笙
南笙 2021-01-20 12:43

I am running a Java batch file from C#. If I run it by double clicking it executes successfully, but if I run it from C# code it gives exception in thread

相关标签:
4条回答
  • 2021-01-20 13:13

    You are most likely missing some of the parameters that would be included in your systems environment variables.

    0 讨论(0)
  • 2021-01-20 13:23

    Try adding the following code as the first line to your batch file.

    @cd /d %~dp0
    
    0 讨论(0)
  • 2021-01-20 13:32

    Try setting working directory like this

    process.StartInfo.WorkingDirectory = "C:\";
    

    Also, try few other options as mentioned here,

    http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/20992653-dabf-4b31-85f7-e7bfbfb4557c

    0 讨论(0)
  • 2021-01-20 13:32

    Do not use batch_process_path + "\" + instead use Path.Combine() to make sure the path is correctly fitted with slashes.

    Also read this "When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable"

    So set it to false.

    0 讨论(0)
提交回复
热议问题