简体   繁体   English

使用Process.Start启动.pl文件

[英]Launching a .pl file using Process.Start

I have been using Process.Start to launch executables (.exe) files. 我一直在使用Process.Start启动可执行文件(.exe)。 Now I need to execute a .pl file with some arguments. 现在,我需要执行带有一些参数的.pl文件。 can I still use Process.Start or I need a different approach? 我仍然可以使用Process.Start还是需要其他方法?

EDIT :- I am having to mark this question unanswered as I am getting the following error when I try to call the perl file from the CSharp code:- (When I call the same from the commandline with the same path and parameters, It works fine) 编辑:-我必须将这个问题标记为未回答,因为当我尝试从CSharp代码调用perl文件时遇到以下错误:-(当我从具有相同路径和参数的命令行中调用相同文件时,它可以正常工作精细)

System.ApplicationException: StartProcess Failed System.ComponentModel.Win32Exception: The specified executable is not a valid application for this OS platform) System.ApplicationException:StartProcess失败System.ComponentModel.Win32Exception:指定的可执行文件不是此OS平台的有效应用程序)

Please note that when I try to call an .exe file from my C# code, I dont see the above error. 请注意,当我尝试从C#代码中调用.exe文件时,看不到上述错误。

EDIT:- Checking the following link now:- How do I call Perl script in C# application? 编辑:-现在检查以下链接:- 如何在C#应用程序中调用Perl脚本? It seems that the ProcessStartInfo constructor has two parameters - fileName and the arguments. 似乎ProcessStartInfo构造函数具有两个参数-fileName和自变量。 You should set Perl.exe as the fileName and the "argument" would be your perl file (.pl) with other arguments It accepts. 您应该将Perl.exe设置为fileName,“参数”将是您的perl文件(.pl),并带有其他参数。 Checking now.... 正在检查...。

You certainly can :) you can also pass it arguments by adding them after the file name in 您当然可以:)也可以通过在文件名中添加参数来传递参数

Process.Start(file.pl args1 args 2);

It will load the file with your default application for .pl files, the other option is to specify the software then pass your file as a parameter providing you have the right software to handle the file it should be fine 它将使用默认的.pl文件应用程序加载文件,另一个选择是指定软件,然后将文件作为参数传递,前提是您拥有正确的软件来处理该文件,应该没事

Process.Start() can be pointed at any file and it will be opened using the default software or that which you specify, it need not be an executable. Process.Start()可以指向任何文件,它将使用默认软件或您指定的软件打开,它不一定是可执行文件。

是的,您可以,Process.Start()带有字符串参数,为此参数传递的内容与在Windows开始->运行对话框中输入相同的字符串时所做的完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM