指定的可执行文件不是此操作系统平台的有效应用程序. [英] The specified executable is not a valid application for this OS platform.'

查看:52
本文介绍了指定的可执行文件不是此操作系统平台的有效应用程序.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到错误 System.ComponentModel.Win32Exception: The specified executable is not a valid application for this OS platform. 当我尝试运行此代码时.

I keep getting the error System.ComponentModel.Win32Exception: The specified executable is not a valid application for this OS platform. when I try to run this code.

看来 myProcess.Start() 行是问题所在.谁能帮帮我.

It seems that the line myProcess.Start() is the problem. Can anyone help me out.

        string python = @"C:\Users\mk\Desktop\A.py";

        // python app to call 
        string myPythonApp = "sum.py";

        // dummy parameters to send Python script 
        int x = 2;
        int y = 5;

        // Create new process start info 
        ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);

        // make sure we can read the output from stdout 
        myProcessStartInfo.UseShellExecute = false;
        myProcessStartInfo.RedirectStandardOutput = true;

        // start python app with 3 arguments  
        // 1st arguments is pointer to itself,  
        // 2nd and 3rd are actual arguments we want to send 
        myProcessStartInfo.Arguments = myPythonApp + " " + x + " " + y;

        Process myProcess = new Process();
        // assign start information to the process 
        myProcess.StartInfo = myProcessStartInfo;

        Console.WriteLine("Calling Python script with arguments {0} and {1}", x, y);

        // start the process 
        myProcess.Start();

    }
}

}

推荐答案

您正在尝试将 A.py 作为可执行文件调用,例如 .exe,它不是(它只是文本,而不是程序集).

You are attempting to call A.py as an executable file, such as a .exe, which it is not (it's just text, not an assembly).

相反,您可以通过 CMD 调用 Python 来运行 A.py,并将 sum.py 作为额外参数传入.

Instead, you can call Python through CMD to run A.py, and pass in sum.py as an extra argument.

这是一个例子:

ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe"); 

// run python from console.
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments = "/C python A.py " + myPythonApp + " " + x + " " + y; 

Process myProcess = new Process(); 
myProcess.StartInfo = myProcessStartInfo;
// start the process 
myProcess.Start();

这篇关于指定的可执行文件不是此操作系统平台的有效应用程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆