asp.net 运行.exe文件和R脚本

本人工作需要将一些别人已经发布的软件等 加入自己的算法,然后发布到网上供其他人使用,大多数其它人的程序都是已经成型的exe文件,这就需要在网页中去调用这些程序。R语言当然可以在C#中直接调用,我这里写的是如何运行已有的R脚本,当然机器上必须先安装R软件。

首先要更改 应用池(application Pool)权限, 在IIS中 找到应用池 然后点属性 在身份(Identity)页中改为"Local System"。

具体方法是用API接口:

首先添加包

using System.IO;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;

public class runOutFile

//先声明

[DllImport("shell32.dll ")]

public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile,
        StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);

 

//运行exe文件

 

public void runTheExe()

{

   string Filename ="exe文件名"

   string Pathname="文件所在目录"

   string args="所需参数"

   ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder(Filename), new StringBuilder(args)或null, 

           new StringBuilder(Pathname), 1);

}

//运行R脚本 R语言是一门应用广泛的统计工具 大致同上

public void runR()

{

   string Filename ="Rscript.exe"                                   //R的脚本运行器

   string Pathname=@"C:/Program Files/R/R-2.12.0/bin"  //R的安装目录

   string args=@"D:/myR.R"                                              //所需运行的脚本

   ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder(Filename), new StringBuilder(args), 

           new StringBuilder(Pathname), 1);

}


 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值