Вопрос

There is this open source software called cdrtfe (located at http://cdrtfe.sourceforge.net/) which supports burning CDs via the command line. When I run the command the basic way by using cmd.exe, it burns correctly with no problems. But when I use C# to create a process while parsing in the required arguments, cdrtfe shows up as if its about to work correctly but then it suddenly complains that there is no space on the disk. I also notice that it didn't even detect that there was a CD writer drive installed. Im not sure why it is behaving in such a way when I call it via C# code but im on the fence here...I cant seem to get around this.

I even tried writing out a bat file with the neccessary commands and calling the bat file using the Process call but it still fails with the same error. However, manually running the very same bat file it creates shows positive results and it starts to burn.

Has anyone got a solution for this?

Here is a small snippet of code I used:-

        String filesargument = "";

        for (int i = 0; i < m_Files.Count; i++)
        {
            filesargument += string.Format("\"{0}\"", m_Files[i].FullName);
            filesargument += " ";
        }

        string path = Path.Combine(
            System.IO.Path.GetDirectoryName(
        System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
            , @"cdrtfe");

        var startInfo = new ProcessStartInfo();
        Process burnProcess = new Process();

        startInfo.Arguments = string.Format(@"/audio {0}/execute /exit /nosplash", filesargument);
        startInfo.UseShellExecute = true;
        startInfo.WorkingDirectory = path;
        startInfo.FileName = @"cdrtfe.exe";

        burnProcess.StartInfo = startInfo;

        burnProcess.Start();
        burnProcess.WaitForExit();

Thanks

Edit: Sorry for the lack of details. This is a WPF application being developed in VS2010 with admin privalges. The code runs under the same account since I am still debugging.

Edit 2: I just tried running the exe without any arguments just to execute it normally and its giving similar results. Its just refusing to detect my CD/DVD drives.

Это было полезно?

Решение 4

I made use of the code @ZahidKakar posted and it worked pretty well but it did not solve the issue with cdrtfe. I have decided to use CDBurnerXP instead (also supports command line burning and even streams back progress) and it works perfectly.

Другие советы

I have an idea that your problem is related to bad configuration of instance ProcessStartInfo. Try to use static method Process.Start(string fileName, string arguments)

First Did You verify your Input String? Is it in the correct format? Secondly You need to RaisingEvents to True and Redirect the Exe output to a Handler from where You can see the Output in your Application GUI. Add Comment if you need further help. I will be glad to help you more in this regard.

I have written sample code for you, hope this would help you more. Kindly rectify it as per your program. Plz dont forget to vote when you got your solution.

private ProcessStartInfo psi;
private Process cmd;
private delegate void InvokeWithString(string text);
public void StartBurning()
{
string filePath = "Your Exe path";
psi = new ProcessStartInfo(filePath);
System.Text.Encoding systemencoding =     System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage);

var _with1 = psi;

_with1.Arguments = "Your Input String";
_with1.UseShellExecute = false;
// Required for redirection
_with1.RedirectStandardError = true;
_with1.RedirectStandardOutput = true;
_with1.RedirectStandardInput = true;
_with1.CreateNoWindow = false;
_with1.StandardOutputEncoding = systemencoding;
// Use OEM encoding for console applications
_with1.StandardErrorEncoding = systemencoding;

// EnableraisingEvents is required for Exited event
cmd = new Process {
    StartInfo = psi,
    EnableRaisingEvents = true
};
cmd.ErrorDataReceived += Async_Data_Received;
cmd.OutputDataReceived += Async_Data_Received;
cmd.Exited += processExited;
cmd.Start();
myProcList.Add(cmd.Id);
cmd.BeginOutputReadLine();
cmd.BeginErrorReadLine();
  }
  private void Async_Data_Received(object sender, DataReceivedEventArgs e)
  {
this.Invoke(new InvokeWithString(Sync_Output), e.Data);
   }
  private void Sync_Output1(string text)
   {
 //This Textbox needs to place at the GUI to check the output Log from your exe. 
txtLog.AppendText(text + Environment.NewLine);
  }
  private void processExited(object sender, EventArgs e)
  {

 this.BeginInvoke(new Action(() => { MessageBox.Show("The burn process   Terminated.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }));
   }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top