【发布时间】:2018-08-21 17:59:23
【问题描述】:
我正在开发一个控制台应用程序,它将所有 spss (.sav) 文件转换为 .csv 文件。为此,我手动创建了一个 SPSS 作业 (spssJob1.spj)(使用一个 .sps 文件),并且我正在遍历所有输入文件(所有 .sav 文件)并尝试通过更新.sps 文件 (text.sps)。但我不知道如何从我的应用程序中调用该作业执行命令。
目前,命令是:
stats C:\Users\10522\Desktop\spssJob1.spj -production
这应该从
执行C:\Program Files\IBM\SPSS\Statistics\22
因为这个 stats 命令只能在这个目录中使用。
所以在我的应用程序中,我需要从这条路径调用这个过程;我可以使用我的应用程序调用一个.exe 文件,但我不知道如何从特定目录调用一个命令。
这是我的代码:
// getting all spss files from the from the input path
FileInfo[] Files = new DirectoryInfo("D:\Input").GetFiles("*.sav");
// looping each files and calling the job
foreach (FileInfo file in Files)
{
if (file.Name != "")
{
// updating the text.sps file for each job
System.IO.File.WriteAllText("D:\Input\text.sps", string.Empty);
System.IO.File.WriteAllText("D:\Input\text.sps", (Content for the file));
// calling the process
var p = new Process();
// this code will work fine simply calling one exe
p.StartInfo = new ProcessStartInfo((@"D:\Input\temp.exe"), "-n")
// instead of this I need to call something like this
// stats C:\Users\10522\Desktop\spssJob1.spj -production from this
// path C:\Program Files\IBM\SPSS\Statistics\22
{
UseShellExecute = false
};
p.Start();
p.WaitForExit();
}
}
【问题讨论】:
标签: c# console-application spss