1

我已经在我的 ubuntu 机器上安装了 mono,我正在尝试启动一个使用 C# 启动其他几个子进程的进程,但是该程序有非常严格的要求,并且由于环境变量问题而无法正确启动。当我在 perl 中使用反引号调用程序时,它工作正常。有人可以告诉我如何在 C# 中模拟反引号函数吗?

        System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo("bash");//perl /home/casey/Downloads/rosetta3.4/rosetta_tools/fragment_tools/make_fragments.pl tempsequence.fa
        ps.RedirectStandardInput=true;
            ps.RedirectStandardOutput = true;
        ps.RedirectStandardError = true;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = ps;
        ps.UseShellExecute = false;
        proc.Start();
        proc.StandardInput.WriteLine("cd "+ projectfolder+"/"+projectname+" ; perl /home/casey/Downloads/rosetta3.4/rosetta_tools/fragment_tools/make_fragments.pl tempsequence.fa;exit;");
            proc.WaitForExit();

这是它在 C# 下运行时生成的错误,它在 perl 中运行良好。

/home/casey/Downloads/sparks-x/bin/buildinp_query.sh: 4: [: /home/casey/Downloads/sparks-x: unexpected operator
/home/casey/Downloads/sparks-x/bin/psiblast.sh: 21: /home/casey/Downloads/sparks-x/bin/psiblast.sh: /blast/bin/blastpgp: not found
Traceback (most recent call last):
  File "/home/casey/Downloads/sparks-x/bin/buildinp.py", line 255, in run1
    buildinp(fphipsiss, fmat, finp)
  File "/home/casey/Downloads/sparks-x/bin/buildinp.py", line 238, in buildinp
    seq1, ssec1, phipsi1, Fphipsi = rdphipsi(fphipsiss)
  File "/home/casey/Downloads/sparks-x/bin/buildinp.py", line 9, in rdphipsi
    for line in file(fn):
IOError: [Errno 2] No such file or directory: 't001_.fasta.phipsi'
sparks failed!

no id specified. parsing filename instead.
INTERMEDIATE: tempsequence.fa
ID: t001 CHAIN: _
File for psipred not found! Generating from scratch instead.
picking fragments with options:
                       DEBUG: 1
            add_pdbs_to_vall: 
                       chain: _
                     cleanup: 1
exclude_homologs_by_pdb_date: 0
                           f: tempsequence.fa
                   fastafile: t001_.fasta
                        homs: 1
                          id: t001
                n_candidates: 1000
                     n_frags: 200
             old_name_format: 0
                  pick_frags: 1
                      porter: 0
                 porter_file: 
                     psipred: 1
                psipred_file: 
                      rundir: /media/d5ad6bd2-65b3-498f-8355-5b2c55ee42b2/top10demo/automate/projects/showerror
                       runid: t001_
                         sam: 0
                    sam_file: 
                 torsion_bin: 0
--------------------------------------------------------------------------------

FILENAME: t001_.fasta
Sequence: GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
running sparks for phi, psi, and solvent accessibility predictions
/home/casey/Downloads/sparks-x/bin/buildinp_query.sh t001_.fasta
running psiblast for sequence: t001_.fasta
At line 180 of file phipsi_ss0.f
Fortran runtime error: Bad real number in item 3 of list input
Aborting: Can't run first SS0 predictor
Error in file: t001_.fasta.phipsi
4

1 回答 1

1

我认为这里的问题是由创建的进程System.Diagnostics有一个默认的 EnvironmentVariables null。在这里查看 System.Diagnostics.ProcessStartInfo() 的定义:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

EnvironmentVariables 属性是这样描述的:

获取文件的搜索路径、临时文件的目录、特定于应用程序的选项和其他类似信息。

而且,进一步看,EnvironmentVariables 文档在这里:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.environmentvariables.aspx

摘录:

提供适用于此进程和子进程的环境变量的字符串字典。默认值为空。

因此,您生成的“bash”外壳根本没有环境变量。如果您希望某些东西在 PATH 上或对您的 shell 可见,则需要确保它们已设置。或者,您可以对所有内容使用绝对路径。

在示例中,以下代码添加了一个 TempPath 环境变量:

myProcess.StartInfo.EnvironmentVariables.Add("TempPath", "/tmp")
myProcess.StartInfo.UseShellExecute = false; 

在更改 EnvironmentVariables 属性后,您必须将 UseShellExecute 属性设置为 false 才能启动进程。

于 2012-09-25T19:13:22.583 回答