Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Stopping Process

Stopping Process

Scheduled Pinned Locked Moved C#
helpcomquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anveshvm
    wrote on last edited by
    #1

    I am using FFMPEG for streaming operations. (https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3D%3D) I started it using the following program

            Process myProcess = new Process();
            myProcess.StartInfo.FileName = @"ffmpeg.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
    
            myProcess.StartInfo.Arguments = "-i input.avi -vcodec copy -acodec copy output.avi";
            myProcess.Start();
    
            StreamWriter myStreamWriter = myProcess.StandardInput;
    
            myStreamWriter.Write("113"); //using ascii of q
            myStreamWriter.Flush();
    
            myStreamWriter.Write('q');
            myStreamWriter.Flush();
    
            myStreamWriter.Close();
    
    
            myProcess.WaitForExit();
            myProcess.Close();
    

    My intention is to close the program when I send "q" from the program (I meant a graceful exit without making any error). But I can't close it by sending 'q' character or its corresponding ascii. When I run the program from the command line and I press q in the keyboard, program immediately gets closed. Can you pls. help me? Thank you regards anvesh

    P 2 Replies Last reply
    0
    • A anveshvm

      I am using FFMPEG for streaming operations. (https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3D%3D) I started it using the following program

              Process myProcess = new Process();
              myProcess.StartInfo.FileName = @"ffmpeg.exe";
              myProcess.StartInfo.UseShellExecute = false;
              myProcess.StartInfo.RedirectStandardInput = true;
      
              myProcess.StartInfo.Arguments = "-i input.avi -vcodec copy -acodec copy output.avi";
              myProcess.Start();
      
              StreamWriter myStreamWriter = myProcess.StandardInput;
      
              myStreamWriter.Write("113"); //using ascii of q
              myStreamWriter.Flush();
      
              myStreamWriter.Write('q');
              myStreamWriter.Flush();
      
              myStreamWriter.Close();
      
      
              myProcess.WaitForExit();
              myProcess.Close();
      

      My intention is to close the program when I send "q" from the program (I meant a graceful exit without making any error). But I can't close it by sending 'q' character or its corresponding ascii. When I run the program from the command line and I press q in the keyboard, program immediately gets closed. Can you pls. help me? Thank you regards anvesh

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      anveshvm wrote:

      Can you pls. help me?

      I believe so; see my ProcessCommunicator[^] article.

      A 1 Reply Last reply
      0
      • A anveshvm

        I am using FFMPEG for streaming operations. (https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3D%3D) I started it using the following program

                Process myProcess = new Process();
                myProcess.StartInfo.FileName = @"ffmpeg.exe";
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.RedirectStandardInput = true;
        
                myProcess.StartInfo.Arguments = "-i input.avi -vcodec copy -acodec copy output.avi";
                myProcess.Start();
        
                StreamWriter myStreamWriter = myProcess.StandardInput;
        
                myStreamWriter.Write("113"); //using ascii of q
                myStreamWriter.Flush();
        
                myStreamWriter.Write('q');
                myStreamWriter.Flush();
        
                myStreamWriter.Close();
        
        
                myProcess.WaitForExit();
                myProcess.Close();
        

        My intention is to close the program when I send "q" from the program (I meant a graceful exit without making any error). But I can't close it by sending 'q' character or its corresponding ascii. When I run the program from the command line and I press q in the keyboard, program immediately gets closed. Can you pls. help me? Thank you regards anvesh

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Come to think of it, you may only need to add a CARRIAGE-RETURN character.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          anveshvm wrote:

          Can you pls. help me?

          I believe so; see my ProcessCommunicator[^] article.

          A Offline
          A Offline
          anveshvm
          wrote on last edited by
          #4

          Thanx for the reply, Its actually a nice article. But I couldn't solve my issue using it. A carriage return is not necessary for this application to close. Pressing a 'q' itself (from keyboard) will give give graceful end to the program. I need not press an additional enter key. And as an additional step of precaution, I made my own console program which requries a 'q' followed by carriage return to close the application, and it worked fine when I use WriteLine from .NET What might be the issue? Its only for ffmpeg that I can't send input stream to. I am anxious to know what might be the issue?

          P 2 Replies Last reply
          0
          • A anveshvm

            Thanx for the reply, Its actually a nice article. But I couldn't solve my issue using it. A carriage return is not necessary for this application to close. Pressing a 'q' itself (from keyboard) will give give graceful end to the program. I need not press an additional enter key. And as an additional step of precaution, I made my own console program which requries a 'q' followed by carriage return to close the application, and it worked fine when I use WriteLine from .NET What might be the issue? Its only for ffmpeg that I can't send input stream to. I am anxious to know what might be the issue?

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I don't know, I'm stumped. But maybe the program reads something internal instead of the input stream. What is ffmpeg? Maybe I can try it.

            A 1 Reply Last reply
            0
            • A anveshvm

              Thanx for the reply, Its actually a nice article. But I couldn't solve my issue using it. A carriage return is not necessary for this application to close. Pressing a 'q' itself (from keyboard) will give give graceful end to the program. I need not press an additional enter key. And as an additional step of precaution, I made my own console program which requries a 'q' followed by carriage return to close the application, and it worked fine when I use WriteLine from .NET What might be the issue? Its only for ffmpeg that I can't send input stream to. I am anxious to know what might be the issue?

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              anveshvm wrote:

              WriteLine

              Oh, yeah, that may actually send a LINEFEED and a CARRIAGE-RETURN. If so, you would have to set the NewLine property.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                I don't know, I'm stumped. But maybe the program reads something internal instead of the input stream. What is ffmpeg? Maybe I can try it.

                A Offline
                A Offline
                anveshvm
                wrote on last edited by
                #7

                ffmpeg produces libraries and programs for handling multimedia. We can convert media files into different formats using ffmpeg. It can also record live streams from a camera in different formats. I am attaching the ffmpeg.exe here. https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3d%3d[^] Here in my code i just copy the audio and video codecs of a file (input.avi) into another file(output.avi). Different parameters can be added in this command, but I just consider the basic operation here.

                        Process myProcess = new Process();
                        myProcess.StartInfo.FileName = @"ffmpeg.exe";
                        myProcess.StartInfo.UseShellExecute = false;
                        myProcess.StartInfo.RedirectStandardInput = true;
                
                        myProcess.StartInfo.Arguments = "-i input.avi -vcodec flv -acodec copy output.flv";
                        myProcess.Start();
                
                        StreamWriter myStreamWriter = myProcess.StandardInput;
                
                        myStreamWriter.Write("113"); //using ascii of q
                        myStreamWriter.Flush();
                
                        myStreamWriter.Write('q');
                        myStreamWriter.Flush();
                
                        myStreamWriter.Close();
                
                
                        myProcess.WaitForExit();
                        myProcess.Close()
                

                ;

                If i run the pgm ( ffmpeg.exe should be placed in same foldr) it starts the conversion from avi to flv. When I press [q] the pgm gets closed gracefully. But I I am not being able to close it by sending 'q' character or its corresponding ascii. :confused:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups