commandline problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nick

    commandline problem?

    Hi all:

    In the winform i want to run commandline with return value(string),
    then display this string in winform textbox.

    anyone has idea about that?

    Thanks

    Nick


  • Dave

    #2
    Re: commandline problem?

    Are you asking how to accept input into your WinForms app via the command line?

    If so:

    public static void Main(string[] args)
    {
    foreach (string arg in args)
    System.Windows. Forms.MessageBo x.Show(arg);
    }

    Executing an application with the above code as the Main entry point and the following command line will produce two message boxes,
    each with one of the arguments specified:

    MyApp.exe "c:\Path\Fi le Name.txt" -Switch1

    --
    Dave Sexton
    dave@www..jwaon line..com
    -----------------------------------------------------------------------
    "nick" <fsheng@ebreath e.co.nz> wrote in message news:uvBwDtsSFH A.3464@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi all:
    >
    > In the winform i want to run commandline with return value(string),
    > then display this string in winform textbox.
    >
    > anyone has idea about that?
    >
    > Thanks
    >
    > Nick
    >
    >[/color]


    Comment

    • nick

      #3
      Re: commandline problem?

      Hi Dave:
      there is the thing:
      i have a executable command for exampl is :abc
      you can type abc in commandline then it will return a string.

      then i want to use winform to do this, so write a C# code doing same
      function as type abc in commandline window and return a string.
      finally show this string in textfields.

      the whole process won't pop up commandline window at all.

      Thanks

      Nick

      "Dave" <NOSPAM-dave@dotcomdata solutions.com> wrote in message
      news:OBEHfMtSFH A.2560@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Are you asking how to accept input into your WinForms app via the command[/color]
      line?[color=blue]
      >
      > If so:
      >
      > public static void Main(string[] args)
      > {
      > foreach (string arg in args)
      > System.Windows. Forms.MessageBo x.Show(arg);
      > }
      >
      > Executing an application with the above code as the Main entry point and[/color]
      the following command line will produce two message boxes,[color=blue]
      > each with one of the arguments specified:
      >
      > MyApp.exe "c:\Path\Fi le Name.txt" -Switch1
      >
      > --
      > Dave Sexton
      > dave@www..jwaon line..com
      > -----------------------------------------------------------------------
      > "nick" <fsheng@ebreath e.co.nz> wrote in message[/color]
      news:uvBwDtsSFH A.3464@tk2msftn gp13.phx.gbl...[color=blue][color=green]
      > > Hi all:
      > >
      > > In the winform i want to run commandline with return[/color][/color]
      value(string),[color=blue][color=green]
      > > then display this string in winform textbox.
      > >
      > > anyone has idea about that?
      > >
      > > Thanks
      > >
      > > Nick
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Dave

        #4
        Re: commandline problem?

        You must change the Project output to "Console Application".

        I think that Console.* uses an existing Console window, or creates one if it doesn't already exist for the current process. Your
        output will go to a new console window in the context of a "Windows Application" Project, however, it will not remain open for user
        input.

        If you look real hard you may see the window pop-up for a second, display your string, and then close.

        I'm not aware of any means for preventing a Console window from closing unless it is running in a "Console Application" Project.

        Anyway, it's probably not a good design to have a Windows app displaying a Console window to display status, etc.

        Use a StatusBar control, MessageBox.Show or EntryLog, etc..

        --
        Dave Sexton
        dave@www..jwaon line..com
        -----------------------------------------------------------------------
        "nick" <fsheng@ebreath e.co.nz> wrote in message news:OCF3DWuSFH A.3184@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Hi Dave:
        > there is the thing:
        > i have a executable command for exampl is :abc
        > you can type abc in commandline then it will return a string.
        >
        > then i want to use winform to do this, so write a C# code doing same
        > function as type abc in commandline window and return a string.
        > finally show this string in textfields.
        >
        > the whole process won't pop up commandline window at all.
        >
        > Thanks
        >
        > Nick
        >
        > "Dave" <NOSPAM-dave@dotcomdata solutions.com> wrote in message
        > news:OBEHfMtSFH A.2560@TK2MSFTN GP09.phx.gbl...[color=green]
        >> Are you asking how to accept input into your WinForms app via the command[/color]
        > line?[color=green]
        >>
        >> If so:
        >>
        >> public static void Main(string[] args)
        >> {
        >> foreach (string arg in args)
        >> System.Windows. Forms.MessageBo x.Show(arg);
        >> }
        >>
        >> Executing an application with the above code as the Main entry point and[/color]
        > the following command line will produce two message boxes,[color=green]
        >> each with one of the arguments specified:
        >>
        >> MyApp.exe "c:\Path\Fi le Name.txt" -Switch1
        >>
        >> --
        >> Dave Sexton
        >> dave@www..jwaon line..com
        >> -----------------------------------------------------------------------
        >> "nick" <fsheng@ebreath e.co.nz> wrote in message[/color]
        > news:uvBwDtsSFH A.3464@tk2msftn gp13.phx.gbl...[color=green][color=darkred]
        >> > Hi all:
        >> >
        >> > In the winform i want to run commandline with return[/color][/color]
        > value(string),[color=green][color=darkred]
        >> > then display this string in winform textbox.
        >> >
        >> > anyone has idea about that?
        >> >
        >> > Thanks
        >> >
        >> > Nick
        >> >
        >> >[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Steve Walker

          #5
          Re: commandline problem?

          In message <uvBwDtsSFHA.34 64@tk2msftngp13 .phx.gbl>, nick
          <fsheng@ebreath e.co.nz> writes[color=blue]
          >Hi all:
          >
          > In the winform i want to run commandline with return value(string),
          >then display this string in winform textbox.
          >
          > anyone has idea about that?[/color]

          Drop a button and a textbox onto a form. Create a batch file
          (C:\test.bat) with something that will generate output (I used "ping
          127.0.0.1"). Add this code to the button click event.


          ProcessStartInf o ps = new ProcessStartInf o(@"C:\test.bat ");
          ps.RedirectStan dardOutput = true;
          ps.UseShellExec ute = false;
          Process p = Process.Start(p s);
          this.textBox1.T ext = p.StandardOutpu t.ReadToEnd();

          Is that what you were after?

          --
          Steve Walker

          Comment

          Working...