Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何运行应用程序并发送文件名?_C#_Openstreetmap - Fatal编程技术网

C# 如何运行应用程序并发送文件名?

C# 如何运行应用程序并发送文件名?,c#,openstreetmap,C#,Openstreetmap,我已加载以下地图: andorra-latest.osm.pbf https://download.geofabrik.de/europe/andorra-latest.osm.pbf azores-latest.osm.pbf https://download.geofabrik.de/europe/azores-latest.osm.pbf cyprus-latest.osm.pbf https://download.geofabrik.de/euro

我已加载以下地图:

andorra-latest.osm.pbf       https://download.geofabrik.de/europe/andorra-latest.osm.pbf
azores-latest.osm.pbf        https://download.geofabrik.de/europe/azores-latest.osm.pbf
cyprus-latest.osm.pbf        https://download.geofabrik.de/europe/cyprus-latest.osm.pbf
我需要合并上面的地图。所以我用它来合并地图。我读书。因此,如果我复制以下命令并粘贴到
命令窗口
,那么它工作正常-它会创建
all.osm.pbf
文件:

因此,将创建所需的文件
all.osm.pbf

但是,现在我想以编程方式调用此命令。我的意思是,我想通过C调用上面的命令。因此,我在控制台应用程序中尝试了以下代码:

static Process process = new Process();

static void Main(string[] args)
{
    process.EnableRaisingEvents = true;
    process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived);
    process.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_ErrorDataReceived);
    process.Exited += new System.EventHandler(process_Exited);

    process.StartInfo.FileName = @"osmconvert.exe";
    process.StartInfo.Arguments = @"osmconvert.exe andorra-latest.osm.pbf --out-o5m | osmconvert.exe - azores-latest.osm.pbf | osmconvert.exe - cyprus-latest.osm.pbf -o=all.osm.pbf";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.RedirectStandardOutput = true;

    process.Start();
    process.BeginErrorReadLine();
    process.BeginOutputReadLine();
}
但我总是看到以下错误:

我的文件位于
D:\Downloads

请问,我做错了什么

更新:

我尝试过这段代码,但错误是相同的:

process.StartInfo.FileName = @"D:\Downloads\osmconvert.exe";
process.StartInfo.Arguments = @"D:\Downloads\osmconvert.exe D:\Downloads\andorra-latest.osm.pbf --out-o5m | D:\Downloads\osmconvert.exe - D:\Downloads\azores-latest.osm.pbf | D:\Downloads\osmconvert.exe - D:\Downloads\cyprus-latest.osm.pbf -o=D:\Downloads\all.osm.pbf";
这种方法:

process.StartInfo.FileName = @"D:\\Downloads\\osmconvert.exe";
process.StartInfo.Arguments = @"D:\\Downloads\\osmconvert.exe D:\\Downloads\\andorra-latest.osm.pbf --out-o5m | D:\\Downloads\\osmconvert.exe - D:\\Downloads\\azores-latest.osm.pbf | D:\\Downloads\\osmconvert.exe - D:\\Downloads\\cyprus-latest.osm.pbf -o=D:\\Downloads\\all.osm.pbf";

我认为问题在于您正在发送
osmconvert.exe
作为第一个命令行参数。可执行文件可能正在尝试打开自身并将其作为地图数据进行处理。这可能会失败,因为它试图以在执行时不可能的方式(读/写)打开

相反,您可以“以编程方式”调用cmd.exe并告诉它执行以下命令:

static Process process = new Process();

static void Main(string[] args)
{
    process.Exited += new System.EventHandler(process_Exited);

    // create a cmd.exe process.
    process.StartInfo.FileName = @"cmd.exe";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardInput = true;
    process.Start();

    var input = process.StandardInput;
    // tell cmd.exe to do your bidding.
    input.WriteLine("osmconvert.exe andorra-latest.osm.pbf --out-o5m | osmconvert.exe - azores-latest.osm.pbf | osmconvert.exe - cyprus-latest.osm.pbf -o=all.osm.pbf");
    // then tell it to exit.
    input.WriteLine("exit");
    // process.Exited event should fire at this point.
    // or you could process.WaitForExit() instead.
}

你到底想干什么?开始处理三个文件?通过管道将输出传输到另一个可执行文件?因为这里的管道没有任何意义。如果您只想用三个文件启动可执行文件,请逐个启动它们。请尝试传递地图的完整路径或相对路径,而不仅仅是文件名。您需要输入所有文件和文件夹的完整路径名。Process类以空环境路径开始,因此找不到可执行文件。@谢谢您的回答。如何给出相关地图?@Learner尝试传递
D:\\Downloads\\azores latest.osm.pbf
而不是
azores latest.osm.pbf