?
Solved

How to run commandline argument in asp.net application

Posted on 2011-10-02
5
Medium Priority
?
525 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:tanu80
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
Kelvin McDaniel earned 750 total points
ID: 36899308
This is an older post, but still effective. It also contains an example for making an async call.

http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx
0
 

Author Comment

by:tanu80
ID: 36899457
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.
0
 
LVL 11

Expert Comment

by:Kelvin McDaniel
ID: 36899481
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.  
0
 
LVL 12

Expert Comment

by:FarWest
ID: 36899797
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
0
 

Author Closing Comment

by:tanu80
ID: 36904387
thanks for the solution.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question