用于运行R批处理作业的ProcessStartInfo [英] ProcessStartInfo for running R batch jobs

查看:95
本文介绍了用于运行R批处理作业的ProcessStartInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下ProcessStartInfo行从网站(asp.net/mono)运行R批处理命令(程序和输出取决于用户):

test.StartInfo = new ProcessStartInfo("/bin/sh","/usr/bin/R CMD BATCH/usr/Scripts/program/usr/Scripts/output");

R batch将仅使用R CMD BATCH从命令行或.sh脚本文件直接运行,但ProcessStartInfo似乎需要完全限定的地址路径.

由于R CMD BATCH的位置可能在服务器之间发生变化,因此我是否可以在没有R CMD BATCH合格路径变量的情况下使用ProcessStartInfo?另外,是否可以动态设置实际的路径变量?

I am running an R batch command from a website (asp.net/mono) using the following ProcessStartInfo line (program and output are user dependent):

test.StartInfo = new ProcessStartInfo("/bin/sh", "/usr/bin/R CMD BATCH /usr/Scripts/program /usr/Scripts/output");

R batch will run directly from the command line or from a .sh script file using just R CMD BATCH but ProcessStartInfo seems to require the fully qualified address path.

As the location of R CMD BATCH may change between servers, is there anyway I can use ProcessStartInfo without the qualifying path variable for R CMD BATCH? Alternatively, is there anyway I can set the actual path variable dynamically?

Many thanks for any suggestions!

推荐答案

好,您需要以某种方式指定目录,对吧?没有奇迹.对于Unix/Linux来说,非常典型的一种方法是在PATH环境变量中放置许多路径,我并不特别喜欢.另外,您需要了解,某些应用程序可以依赖于应用程序的工作目录",但是在类Unix上则不是这种情况.默认情况下,工作目录不包含在传递中,因此许多命令行看起来像"./application_executable_module"和"./".因此,您需要设计一些方法来设置批处理文件的路径,例如通过初始配置或安装过程进行设置,这可以在某些配置文件中指定目录.您可以通过输入程序集的主要可执行模块(即可执行目录)的位置找到配置文件的位置.请参阅我最近的答案中的食谱:
如何找到我的程序目录 [#!/bin/bash".因此,您可以改为执行以下操作:
Well, you need to specify the directory somehow, right? There is no such thing as a miracle. One way quite typical for Unix/Linux is putting many paths in the PATH environment variable, which I don''t particularly like. Also, you need to understand, that some application can rely on the "working directory" of the application, but this is not the case on the Unix-like; the working directory is not included in the pass by default, that way many command lines look like "./application_executable_module", with "./". So you need to devise some method of setting the path to your batch file, such as set up by initial configuration or installation procedure which can prescribe the directory in some configuration file. You can find the configuration file location by the location of the main executable module of your entry assembly, that is, the executable directory. Please see the recipe in my recent answer:
How to find my programs directory[^].

Also, you normally don''t need to use "/bin/sh", which is in fact just another application, one of the command interpreters. Besides, its location is always included in the PATH environment variable. When you execute a shell script, you don''t normally specify it, right? And this is because the shell application is prescribed in the script/batch file itself, like in this form: "#!/bin/bash". So, you can do this instead:
test.StartInfo = new ProcessStartInfo("/usr/bin/R", "CMD BATCH /usr/Scripts/program /usr/Scripts/output");



在此代码行中,我只是将您的命令行复制到应用程序集的主要可执行模块的名称及其命令行参数中,包括所有绝对路径.在实际功能的应用程序中,无论相对还是绝对,硬编码路径都不会有用.应始终在运行时根据一些配置文件,应用程序位置,用户特殊文件夹"等来计算路径.

—SA



In this code line, I just copied your command line broken into the name of main executable module of your application assembly and its command line parameters, with all your absolute path. In really functional applications, there are no cases when a hard-coded path can be useful, no matter it if is relative or absolute. The path should be always calculated during run time based on some configuration file(s), application location, user "special folders", etc.

—SA


这篇关于用于运行R批处理作业的ProcessStartInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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