Search code examples
c#cmdmasm

Compile an .asm file through c# using cmd


I want to compile an .asm file placed in bin folder in the masm through c#.I have tried multiple methods like process.start but nothing helps.It opens the cmd but the command "ml" never executes.It either open the pwb.exe(MASM) or the 'file.asm' in notepad.I give these arguments to CMD "path\ml file.asm" which works fine manually.ml is a command used to compile .asm files. One of the method I used is following

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = @"C:\WINDOWS\system32\cmd.exe";
startInfo.Arguments = "C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml file.asm";

process.StartInfo = startInfo;
process.Start();

Solution

  • If you want to start the process in this way, you'll need to put quotes round the path, due to the spaces:

    startInfo.Arguments = @"""C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml"" file.asm";
    

    (In a verbatim string literal, you include double-quotes by doubling them.)

    Alternatively, if ml is actually an executable (I know nothing about masm) you could just use:

    startInfo.FileName = @"C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml.exe";
    startInfo.Arguments = "file.asm";