-2

I have written a c# program. Now I would like to convert .avi files in .mp3 files with lame. I've installed the command-line application. Manually it works fine. Now I would like to automate the process:

C# Application => starts Console and run "lame.exe" with the parameters.

I would like to convert more than one file. How can I do this?

Thanks

AlanT
  • 3,627
  • 20
  • 28
  • 1
    Maybe [Process.Start](https://msdn.microsoft.com/en-us/library/e8zac0ca(v=vs.110).aspx) can help? – Pikoh Jun 10 '16 at 11:14
  • A simple google search "c# run command line process" would give you the answer and it is faster than posting this question. – Camilo Terevinto Jun 10 '16 at 11:20
  • 1
    Lol, i wonder what you have written then till now in your console program :) – Icepickle Jun 10 '16 at 11:21
  • 1
    Possible duplicate of [Run Command Prompt Commands](http://stackoverflow.com/questions/1469764/run-command-prompt-commands) – Draken Jun 10 '16 at 11:23

4 Answers4

2

I don't know how lame works but can't you get a list of all the files you want to convert, iterate through the list with a foreach loop and run the "lame.exe" for every file?

0

If you can call Lame manually using CMD you should be available to do the same with this:

public void ConvertFileWithLame(string pathToLame, string fileToConvert){
     // Use ProcessStartInfo class.
     ProcessStartInfo startInfo = new ProcessStartInfo(pathToLame, fileToConvert);

     try{
          // Start the process with the info we specified.
          // Call WaitForExit and then the using-statement will close.
          using (Process exeProcess = Process.Start(startInfo)){
               exeProcess.WaitForExit();
          }
     }
     catch{
          // Log error.
     }
}

P.D: Remember that your command must be in your PATH, or indicates the path on the "/path/commandName.exe"

Nestoraj
  • 722
  • 2
  • 6
  • 19
-1

What you could try to do is see if lame.exe accepts multiple arguments for filenames, so then instead of iterating over the filenames, you can just add them in like below

Process.Start("lame.exe", "file1 file2 file3 etc");
TechnicalTophat
  • 1,655
  • 1
  • 15
  • 37
daniel
  • 132
  • 7
-1

all you have to do is implement a foreach loop for a Directory.GetFiles, then within the foreach loop use a Process.Start to run your command. Please see below for example code:

foreach(var t in Directory.GetFiles("path"))
{
  System.Diagnostics.Process.Start("cmd.exe", $"lame command here with interpolated values (t will point to full path of file)");
}
TechnicalTophat
  • 1,655
  • 1
  • 15
  • 37
  • I like how you assume all the files are in the same directory AND that the OP is using Visual Studio 2015 /C# 6 – Camilo Terevinto Jun 10 '16 at 11:18
  • @cFrozenDeath Interpolation can be swapped with String formatting in about 5 seconds. The same goes for the GetFiles, just swap it with an IEnumerable of string file paths, but then the program will be less dynamic. Create a front end that copies selected audio files to a ProgramData folder, and your issue is solved – TechnicalTophat Jun 10 '16 at 11:23
  • You are assuming that the OP knows what string interpolation is, and by looking at the question, the most likely case is that the OP does not. – Camilo Terevinto Jun 10 '16 at 11:26
  • @cFrozenDeath however, It's a google away. I understand that he might not know, but in the interest of expanding fellow developers knowledge, I threw that in there to help him with his knowledge – TechnicalTophat Jun 10 '16 at 11:30