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. Send input to CMD from WINFORM

Send input to CMD from WINFORM

Scheduled Pinned Locked Moved C#
questiontutorial
3 Posts 3 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.
  • H Offline
    H Offline
    Haim Nachum
    wrote on last edited by
    #1

    Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?

    R L 2 Replies Last reply
    0
    • H Haim Nachum

      Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?

      R Offline
      R Offline
      riced
      wrote on last edited by
      #2

      Does your command end with CR+LF? It's just a guess but I think you need to send the equivalent of pressing Enter at a command prompt (i.e. in Cmd window).

      Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

      1 Reply Last reply
      0
      • H Haim Nachum

        Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Your app has a lot of problems with the console because console window doesn't belong to the caller process.If you want be able to read or write to console from Win forms in the same way like console application you should call AllocConsole or AttachConsole native functions to create or assign console window that belong to your windows forms app,not just to external process.To close current process console window you should call FreeConsole function.See some sample code here.

        Life is a stage and we are all actors!

        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