Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CLI conversion runs indefinitely when called from a .NET app #126

Open
Developer-exe opened this issue May 8, 2021 · 0 comments
Open

Comments

@Developer-exe
Copy link

I currently experiment with the VGAudio CLI application. The app I'm trying to make calls the CLI with a set of parameters.
The application then reads the standard output of the CLI to get a result of the conversion (and the time elapsed, if applicable).

The main issue when calling the CLI is that it doesn't close itself upon converting to certain file formats. It keeps running in the background (even though the conversion is finished) leaving the converted file locked.

A summary of the file formats

The file formats currently used by the app for the conversion:

  • WAV (works)
  • DSP (runs indefinitely)
  • IDSP (runs indefinitely)
  • BRSTM (runs indefinitely)
  • BCSTM (runs indefinitely)
  • BFSTM (runs indefinitely)
  • HPS (runs indefinitely)
  • ADX (works)
  • HCA (works)

The only ones that work with all approaches are WAV and the CRIWARE audio formats (ADX and HCA).
When converting the other formats (DSP, IDSP, BRSTM, BCSTM, BFSTM, HPS) directly using the command prompt, the CLI "hangs" for a second before starting the conversion. This is not the case for the WAV, ADX and HCA file formats.

Different ways to tackle this issue

I've tried several approaches:

  1. Executing the command, waiting for it to exit and then read the output with proc.StandardOutput.ReadToEnd()
// This doesn't work with certain file formats
var process = Process.Start(processInfo);
process.WaitForExit();
output = proc.StandardOutput.ReadToEnd();
  1. Executing the command and appending the lines using proc.StandardOutput.ReadLine()
// This one always works and is the thing I've been using up until now
var process = Process.Start(processInfo);
while (!process.StandardOutput.EndOfStream)
{
   output += process.StandardOutput.ReadLine() + "\r\n";
}
  1. Running the process asynchronously and appending the lines using DataReceivedEventHandler
// This one doesn't work with the same file formats as the first approach
var tcs = new TaskCompletionSource<int>();
var process = new Process
{
   StartInfo = processInfo,
   EnableRaisingEvents = true
};

process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
   if (!String.IsNullOrEmpty(e.Data))
      {
         MessageBox.Show(e.Data);
         output += e.Data + "\r\n";
      }
});

process.Exited += (sender, args) =>
{
   tcs.SetResult(process.ExitCode);
   process.Dispose();
};

process.Start();
return tcs.Task;
  1. Not redirecting the output and show the command line instead
// This one always works but then the app can't read the output
processInfo.RedirectStandardOutput = false;
processInfo.UseShellExecute = true;

The reason I'd like to switch to the third approach (asynchronous) is that I don't want the CLI to hang the application until the conversion is complete. The problem is that using DataReceivedEventHandler asynchronously makes the CLI keep running in the background as if I waited for it to exit and then read the output with proc.StandardOutput.ReadToEnd() synchronously.

Is there a different way the CLI handles the CRIWARE audio formats from the other ones (DSP, IDSP, BRSTM, BCSTM, BFSTM, HPS)?
Could the conversion process be somehow unified or is the problem somewhere else?
Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant