从 exe 文件运行方法
我需要从 exe 文件调用方法
ProcessStartInfo startInfo = new ProcessStartInfo(@"exeParser.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.CreateNoWindow = false;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = ??
我不知道如何调用方法并传递参数
请帮忙吗?
可执行文件是我的,但我在使用网络应用程序中的内容时遇到问题,所以我认为最好将其称为进程
谢谢
I need to call a method from an exe file
ProcessStartInfo startInfo = new ProcessStartInfo(@"exeParser.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.CreateNoWindow = false;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = ??
I don't know how to call a method and pass parameters
Any help please??
The executable is mine but I'm having trouble using the things in a web app so I thought it would be better to call it as a process
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可执行文件只有一个入口点,通常称为“Main”。
要调用特定方法,应用程序必须公开方法名称及其参数的一个(或多个)命令行参数。这意味着更改应用程序以解释这些参数并调用适当的方法。
您将需要修改您的“exeParser”以接受参数,然后对这些参数进行操作。
例如,您可以添加:
然后解析它以获取名称和参数列表。
如果您只有一两个方法,您可以对开关进行硬编码:
如果您有更多方法或想要使代码更通用,那么您需要使用反射来获取方法并调用它。
Executables only have one entry point usually called "Main".
To call a specific method the application would have to expose a command line argument (or several) for the method name and its arguments. This would mean changing the application to interpret those arguments and call the appropriate method.
You will need to modify your "exeParser" to accept arguments and then act on those.
For example you'd could add:
Then parse this to get the name and list of arguments.
If you only have one or two methods you could hardcode the switch:
If you have more or want to make the code more generic then you'd need to use reflection to get the method and call it.
不能,除非该方法在程序集中公开公开。
当然,如果可执行文件是未混淆的 .NET .exe,那么您可能可以使用 Reflector 之类的工具来反汇编代码并将其复制到您的程序中(不推荐),但您必须检查这样做的合法性如果您不拥有相关的可执行文件。
You can't, unless the method is publicly exposed in an assembly.
Of course, if the executable were an un-obfuscated .NET .exe, then presumably you could use something like Reflector to disassemble the code and replicate it in your program (not recommended), BUT you would have to check the legality of doing that if you don't own the executable in question.