Napisałem program, który kompiluje pliki moi .cs użyciu csc.exe:Oczekiwane zachowanie z białej przestrzeni w linii poleceń
namespace myCompiler
{
public partial class Form1 : Form
{
string compilerFolder;
string outputFolder;
string projectFile;
string output = @" /out:";
public Form1()
{
InitializeComponent();
}
private void startCompile_Click(object sender, EventArgs e)
{
Compile();
}
public void findCompile_Click(object sender, EventArgs e)
{
DialogResult result1 = folderBrowserDialog1.ShowDialog();
compilerFolder = folderBrowserDialog1.SelectedPath;
MessageBox.Show(compilerFolder);
cscLabel.Text = compilerFolder;
}
private void outputCompile_Click(object sender, EventArgs e)
{
DialogResult result2 = folderBrowserDialog2.ShowDialog();
outputFolder = folderBrowserDialog2.SelectedPath;
outputLabel.Text = (outputFolder);
MessageBox.Show(outputFolder);
}
private void findProject_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
projectFile = openFileDialog1.FileName;
projectLabel.Text = (projectFile);
MessageBox.Show(projectFile);
}
}
public void Compile()
{
try
{
Process compile = new Process();
string outputExe = fileName.Text;
string compiler = compilerFolder + @"\csc.exe";
string arGs = output + outputFolder + @"\" + outputExe + " " + projectFile;
compile.StartInfo.FileName = (compiler);
compile.StartInfo.Arguments = (arGs);
compile.StartInfo.RedirectStandardOutput = true;
compile.StartInfo.UseShellExecute = false;
compile.Start();
string stdOutput = "";
while (!compile.HasExited)
{
stdOutput += compile.StandardOutput.ReadToEnd();
MessageBox.Show(stdOutput);
}
}
catch (Exception errorMsg)
{
MessageBox.Show(errorMsg.Message);
}
}
private void testButton_Click(object sender, EventArgs e)
{
MessageBox.Show(projectFile);
MessageBox.Show(compilerFolder);
}
}
}
kompilacja przebiega instrukcji ale nie daje rezultatów, tylko szybki błysk czarny ekran konsoli.
zasadzie to, co wydaje się dzieje, gdy wszystkie ciągi są przetwarzane w wierszu poleceń jako argumenty dla procesu, katalog .cs źródło projekt jest podzielony przez każde białej przestrzeni tj c:\users\%username%\Documents\Visual Studio 2010\
jest podzielone jak c:\users\%username%\Documents\Visual then Studio
następnie 2010\Projects\Myproject\myproj.cs
, a następnie kompilacja nie powiedzie się.
Potrzebne są podwójne cudzysłowy wokół ścieżki do plików ze spacjami. –
Jeśli naprawdę chcesz opublikować zdjęcie, opublikuj link, a inni użytkownicy mogą edytować swój wpis i zmienić link do zdjęcia :) Wygląda na to, że opisałeś swój problem wystarczająco, ale – Sayse
Kompilowanie programów jest wbudowaną funkcją .NET , użyj przestrzeni nazw System.CodeDom. –