Link to home
Start Free TrialLog in
Avatar of tanu80
tanu80

asked on

How to run commandline argument in asp.net application

Hi Expert,

i am bit confused about to converting a swf file to .flv format dynamically, though i got a tool that convert it but it needs a command line argument to be executed in the server to do this.I am bit confused how i ll do this because i have developed the application in asp.net with c#, is there any possible chance to do this means when the user will submit the request for conversion that time the swf2videocmd xxx.swf -out myvideo.avi -f avi -vcodec bgr24 -vbr 5000000 -acodec mp3 -asr 44100 -abr 128000 -ac 2 will be executed in the server to get the desired out put.I need some solution to do this.


Thanks
Tanayya
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tanu80
tanu80

ASKER

Hi ,

thanks for the suggestion but bit worry to use the code because the exe is present in the C:\Program Files\Moyea\SWF to Video SDK\swf2videocmd and how i ll use it.

I am using below set of code


 protected void Page_Load(object sender, EventArgs e)
    {
       

        ExecuteCommandAsync("swf2videocmd d:\\tanayya\\theme.swf -out d:\\tanayya\\Mona.avi -f avi -vcodec bgr24 -vbr 5000000 -acodec mp3 -asr 44100 -abr 128000 -ac 2");
        //ExecuteCommandAsync("d:\\tanayya\\theme.swf ");
     

    }

    public void ExecuteCommandSync(object command)
    {
        try
        {
            // create the ProcessStartInfo using "cmd" as the program to be run,
            // and "/c " as the parameters.
            // Incidentally, /c tells cmd that we want it to execute the command that follows,
            // and then exit.
            System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("SWF to Video SDK Command Prompt.exe", " " + command);

            // The following commands are needed to redirect the standard output.
            // This means that it will be redirected to the Process.StandardOutput StreamReader.
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            // Do not create the black window.
            procStartInfo.CreateNoWindow = true;
            // Now we create a process, assign its ProcessStartInfo and start it
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            // Get the output into a string
            string result = proc.StandardOutput.ReadToEnd();
            // Display the command output.
            Response.Write(result);
        }
        catch (Exception objException)
        {
            // Log the exception
        }
    }
    public void ExecuteCommandAsync(string command)
{
   try
   {
    //Asynchronously start the Thread to process the Execute command request.
    Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
    //Make the thread as background thread.
    objThread.IsBackground = true;
    //Set the Priority of the thread.
    objThread.Priority = ThreadPriority.AboveNormal;
    //Start the thread.
    objThread.Start(command);
   }
   catch (ThreadStartException objException)
   {
    // Log the exception
   }
   catch (ThreadAbortException objException)
   {
    // Log the exception
   }
   catch (Exception objException)
   {
    // Log the exception
   }
}

I am not getting the out put.
A few things I see...

1. Make sure you're disposing of things properly. I'm not sure but I don't think you are... And I'm not in front of a computer so I can't verify that. Put it this way; in the code you've provided, any object that has a Close() or Dispose() method needs to had that/those methods called when you are finished using those objects.

2. Make sure that you are putting quotes around any paths that you're passing to the OS. It needs those to know that it should treat those strings as full paths.

3. I'd suggest letting the window be visible until you're sure your code is working. Also, add a line where the window won't disappear until you dismiss it. If I'm not mistaken that's Console.ReadKey().

Try those and see how it goes.

2.  
I think it is better to isolate the whole conversion call from the ASP.NET process
1) make a table in your database that will hold the queue of requests with details and status,
2) Make a windows service that monitor that table and excute conversions (you can use workitems for multible threads) 3) your ASP.NEt will insert on that table , and will check when the user refresh (or automatic refresh) is done on that page if he has completed conversion, or even show the progress

this way asp.net process will not be chuncked with sub-threads
Avatar of tanu80

ASKER

thanks for the solution.