Stand alone Executable return argument

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

    Stand alone Executable return argument

    Hi,
    I have a very serious issue at hand. I have created a small C# Console App
    (Csd.exe) that collects a list of files as its argument and generates their
    Md5 sets.
    This application is used by other applications in my dept, which simply call
    this Csd.exe app and passing a list of files.
    I want to ask how can I return a value from this Csd.exe application as an
    indicator or a signal to the calling app that Csd.exe has finished working.
    The problem is that the main component of my Csd.exe is a

    public static void main(string[] args)
    {
    //All the work
    //And that is it (done)!
    //Here i want to enter a return int or a bool (true) so that the caller
    can know
    //that i am finished processing....
    }

    The Static void main does not let me return anything. How can i do that.

    Please HELP!

    Thanks and Regards
    Sunny

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Stand alone Executable return argument

    Sunny,

    You really aren't going to be able to pass a value back through the
    executable. The best you could do is pass an integer back to the process
    that triggered you.

    If possible, you should refactor this code out into a component, and
    integrate that component into the other applications that need it. It would
    be easy enough to expose this as a .NET and a COM component, which should
    allow you to access it from almost anywhere.

    If you need to keep this as an executable, then you might want to
    consider having it write out files to another directory, which you can
    relate to the original files, which have the MD5 hash in them, or store the
    hashes in some other persistant format (like a database) where the other
    applications can get to it.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
    news:61F243CF-E0DD-4DE5-BAB3-E8DC70D3A03F@mi crosoft.com...[color=blue]
    > Hi,
    > I have a very serious issue at hand. I have created a small C# Console App
    > (Csd.exe) that collects a list of files as its argument and generates
    > their
    > Md5 sets.
    > This application is used by other applications in my dept, which simply
    > call
    > this Csd.exe app and passing a list of files.
    > I want to ask how can I return a value from this Csd.exe application as an
    > indicator or a signal to the calling app that Csd.exe has finished
    > working.
    > The problem is that the main component of my Csd.exe is a
    >
    > public static void main(string[] args)
    > {
    > //All the work
    > //And that is it (done)!
    > //Here i want to enter a return int or a bool (true) so that the caller
    > can know
    > //that i am finished processing....
    > }
    >
    > The Static void main does not let me return anything. How can i do that.
    >
    > Please HELP!
    >
    > Thanks and Regards
    > Sunny
    >[/color]


    Comment

    • Sunny

      #3
      Re: Stand alone Executable return argument

      I appreciate all the help, I am in fact writing out a set of Xml files at
      this time as my work process and at the end of the process i am infact
      invoking a third application that in turns (indirectly) signals to my caller
      as a signal of my work completion. However this app is being used almost by
      all the other apps and i have been told to return a signal to the caller that
      i have finished my work in addition to the files written out, since they
      don't always want to go and read the files as such.

      But I think there has got to be a way for the. static void main(string[]
      args) to return some signal values to their callers, this simply defies all
      logic that this is not prossible in this scenario...
      would look forward to any more suggestions. . .

      Thanks for the Help,

      With Regards
      Sunny



      "Nicholas Paldino [.NET/C# MVP]" wrote:
      [color=blue]
      > Sunny,
      >
      > You really aren't going to be able to pass a value back through the
      > executable. The best you could do is pass an integer back to the process
      > that triggered you.
      >
      > If possible, you should refactor this code out into a component, and
      > integrate that component into the other applications that need it. It would
      > be easy enough to expose this as a .NET and a COM component, which should
      > allow you to access it from almost anywhere.
      >
      > If you need to keep this as an executable, then you might want to
      > consider having it write out files to another directory, which you can
      > relate to the original files, which have the MD5 hash in them, or store the
      > hashes in some other persistant format (like a database) where the other
      > applications can get to it.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
      > news:61F243CF-E0DD-4DE5-BAB3-E8DC70D3A03F@mi crosoft.com...[color=green]
      > > Hi,
      > > I have a very serious issue at hand. I have created a small C# Console App
      > > (Csd.exe) that collects a list of files as its argument and generates
      > > their
      > > Md5 sets.
      > > This application is used by other applications in my dept, which simply
      > > call
      > > this Csd.exe app and passing a list of files.
      > > I want to ask how can I return a value from this Csd.exe application as an
      > > indicator or a signal to the calling app that Csd.exe has finished
      > > working.
      > > The problem is that the main component of my Csd.exe is a
      > >
      > > public static void main(string[] args)
      > > {
      > > //All the work
      > > //And that is it (done)!
      > > //Here i want to enter a return int or a bool (true) so that the caller
      > > can know
      > > //that i am finished processing....
      > > }
      > >
      > > The Static void main does not let me return anything. How can i do that.
      > >
      > > Please HELP!
      > >
      > > Thanks and Regards
      > > Sunny
      > >[/color]
      >
      >
      >[/color]

      Comment

      • Bob Grommes

        #4
        Re: Stand alone Executable return argument

        Just change public static void main to public static int main, and return
        whever error code you want to return to the process. Then any other process
        running your EXE can check the return code.

        --Bob

        "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
        news:61F243CF-E0DD-4DE5-BAB3-E8DC70D3A03F@mi crosoft.com...[color=blue]
        > Hi,
        > I have a very serious issue at hand. I have created a small C# Console App
        > (Csd.exe) that collects a list of files as its argument and generates
        > their
        > Md5 sets.
        > This application is used by other applications in my dept, which simply
        > call
        > this Csd.exe app and passing a list of files.
        > I want to ask how can I return a value from this Csd.exe application as an
        > indicator or a signal to the calling app that Csd.exe has finished
        > working.
        > The problem is that the main component of my Csd.exe is a
        >
        > public static void main(string[] args)
        > {
        > //All the work
        > //And that is it (done)!
        > //Here i want to enter a return int or a bool (true) so that the caller
        > can know
        > //that i am finished processing....
        > }
        >
        > The Static void main does not let me return anything. How can i do that.
        >
        > Please HELP!
        >
        > Thanks and Regards
        > Sunny
        >[/color]


        Comment

        • Sunny

          #5
          Re: Stand alone Executable return argument

          Hi Nicholas great to see you finally after a long time.
          Thanks for the info, infact i am writing out an xml file as my work process
          and at the end my app is invoking a third application that signals to my
          caller as a signal of my work completion, but this app is being used by a lot
          of apps in my dept and there is a req now that it must return a signal value
          so that the caller does not always have to go and check something else to
          find out if i have finished.
          I was thinking there would be a better way to return a status signal to the
          callers even in a static void main implementations

          public static void main(string[] args)
          {
          //All the work
          myInternalClass mc = new myInternalClass (args);
          //Now finished and return something
          }

          Thanks for all the help, and welcome for more suggestions. ..

          With Regards
          Sunny



          "Nicholas Paldino [.NET/C# MVP]" wrote:
          [color=blue]
          > Sunny,
          >
          > You really aren't going to be able to pass a value back through the
          > executable. The best you could do is pass an integer back to the process
          > that triggered you.
          >
          > If possible, you should refactor this code out into a component, and
          > integrate that component into the other applications that need it. It would
          > be easy enough to expose this as a .NET and a COM component, which should
          > allow you to access it from almost anywhere.
          >
          > If you need to keep this as an executable, then you might want to
          > consider having it write out files to another directory, which you can
          > relate to the original files, which have the MD5 hash in them, or store the
          > hashes in some other persistant format (like a database) where the other
          > applications can get to it.
          >
          > Hope this helps.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
          > news:61F243CF-E0DD-4DE5-BAB3-E8DC70D3A03F@mi crosoft.com...[color=green]
          > > Hi,
          > > I have a very serious issue at hand. I have created a small C# Console App
          > > (Csd.exe) that collects a list of files as its argument and generates
          > > their
          > > Md5 sets.
          > > This application is used by other applications in my dept, which simply
          > > call
          > > this Csd.exe app and passing a list of files.
          > > I want to ask how can I return a value from this Csd.exe application as an
          > > indicator or a signal to the calling app that Csd.exe has finished
          > > working.
          > > The problem is that the main component of my Csd.exe is a
          > >
          > > public static void main(string[] args)
          > > {
          > > //All the work
          > > //And that is it (done)!
          > > //Here i want to enter a return int or a bool (true) so that the caller
          > > can know
          > > //that i am finished processing....
          > > }
          > >
          > > The Static void main does not let me return anything. How can i do that.
          > >
          > > Please HELP!
          > >
          > > Thanks and Regards
          > > Sunny
          > >[/color]
          >
          >
          >[/color]

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Stand alone Executable return argument

            Sunny,

            You could do a number of things, but you won't be able to get a return
            value back through the parameters, or through the return value. The entry
            point for the application can only return an integer (which does not meet
            your needs) and it can not modify the command line arguments. Any signal
            that you send (perhaps an event, not the kind in .NET, but the
            synchronization object) would have to be something that the other programs
            actively listen for.

            Because of these needs, it really is a better idea if you place it in a
            component and have the clients or something else call the component. This
            way, you can be more sure when the method completes, (instead of waiting for
            an event, you just wait until the method call completes).


            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
            news:EFA8ED86-7C2A-43A0-8264-DFBFA41E7BD8@mi crosoft.com...[color=blue]
            >I appreciate all the help, I am in fact writing out a set of Xml files at
            > this time as my work process and at the end of the process i am infact
            > invoking a third application that in turns (indirectly) signals to my
            > caller
            > as a signal of my work completion. However this app is being used almost
            > by
            > all the other apps and i have been told to return a signal to the caller
            > that
            > i have finished my work in addition to the files written out, since they
            > don't always want to go and read the files as such.
            >
            > But I think there has got to be a way for the. static void main(string[]
            > args) to return some signal values to their callers, this simply defies
            > all
            > logic that this is not prossible in this scenario...
            > would look forward to any more suggestions. . .
            >
            > Thanks for the Help,
            >
            > With Regards
            > Sunny
            >
            >
            >
            > "Nicholas Paldino [.NET/C# MVP]" wrote:
            >[color=green]
            >> Sunny,
            >>
            >> You really aren't going to be able to pass a value back through the
            >> executable. The best you could do is pass an integer back to the process
            >> that triggered you.
            >>
            >> If possible, you should refactor this code out into a component, and
            >> integrate that component into the other applications that need it. It
            >> would
            >> be easy enough to expose this as a .NET and a COM component, which should
            >> allow you to access it from almost anywhere.
            >>
            >> If you need to keep this as an executable, then you might want to
            >> consider having it write out files to another directory, which you can
            >> relate to the original files, which have the MD5 hash in them, or store
            >> the
            >> hashes in some other persistant format (like a database) where the other
            >> applications can get to it.
            >>
            >> Hope this helps.
            >>
            >>
            >> --
            >> - Nicholas Paldino [.NET/C# MVP]
            >> - mvp@spam.guard. caspershouse.co m
            >>
            >> "Sunny" <Sunny@discussi ons.microsoft.c om> wrote in message
            >> news:61F243CF-E0DD-4DE5-BAB3-E8DC70D3A03F@mi crosoft.com...[color=darkred]
            >> > Hi,
            >> > I have a very serious issue at hand. I have created a small C# Console
            >> > App
            >> > (Csd.exe) that collects a list of files as its argument and generates
            >> > their
            >> > Md5 sets.
            >> > This application is used by other applications in my dept, which simply
            >> > call
            >> > this Csd.exe app and passing a list of files.
            >> > I want to ask how can I return a value from this Csd.exe application as
            >> > an
            >> > indicator or a signal to the calling app that Csd.exe has finished
            >> > working.
            >> > The problem is that the main component of my Csd.exe is a
            >> >
            >> > public static void main(string[] args)
            >> > {
            >> > //All the work
            >> > //And that is it (done)!
            >> > //Here i want to enter a return int or a bool (true) so that the
            >> > caller
            >> > can know
            >> > //that i am finished processing....
            >> > }
            >> >
            >> > The Static void main does not let me return anything. How can i do
            >> > that.
            >> >
            >> > Please HELP!
            >> >
            >> > Thanks and Regards
            >> > Sunny
            >> >[/color]
            >>
            >>
            >>[/color][/color]


            Comment

            • Stoitcho Goutsev \(100\) [C# MVP]

              #7
              Re: Stand alone Executable return argument

              Hi Sunny,
              [color=blue]
              > The Static void main does not let me return anything. How can i do that.[/color]

              Main method can return an integer. The caller can check the return value
              using its prcess handler or in realm of .NET using object of the Process
              class.

              If you only want to signal when the *exe* finish you have options. Look at
              the Process class
              You are going to use that class either to start the *exe* or to attach to
              already running one.

              Then your options are:
              1. To block the caller until the other process finishes -
              Process.WaitFor Exit and then if you need to check Process.ExitCod e, which is
              whatever integer the *exe*'s main method returns
              2. To check periodically Porcess.HasExit ed and if it has to get the ExitCode
              3. To hook on Exited event. It will be fired as soon as the process exits.
              And then again you can check its ExitCode.

              Even thought the process may exited long time ago its ExitCode will stay
              valid until you dispose the process object (or close the process handle in
              terms of Win32 API).

              You can dispose the process by call its Dispose or you can leave this to the
              the GC.

              If you need to communicate big chunk of data, though, what you can do is
              either to use files, or redirect the standart input and output. I believe
              that using sockets or .NET remoting isn't worth it. Actually, do you have
              some options here as well.

              --
              HTH
              Stoitcho Goutsev (100) [C# MVP]



              Comment

              Working...