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. The Lounge
  3. Expect Library

Expect Library

Scheduled Pinned Locked Moved The Lounge
comtoolstutorialquestion
18 Posts 9 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.
  • T Offline
    T Offline
    Tom Archer
    wrote on last edited by
    #1

    Has anyone used this library in order to control a command prompt from their application? I need to find a tool that will enable my application to run a command that is passed from another application. The trick is that the command may be something that needs additional input. For example, App A could call my app (App B) and tell it to run a command-line utility that requires a logon. My app would need to pass back exactly what a user would see in a command window so that App B can send additional information. I'm told that the Expect library does this and wanted to know if anyone here has used it and can confirm that. Cheers, Tom Archer - Archer Consulting Group
    "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

    K T 2 Replies Last reply
    0
    • T Tom Archer

      Has anyone used this library in order to control a command prompt from their application? I need to find a tool that will enable my application to run a command that is passed from another application. The trick is that the command may be something that needs additional input. For example, App A could call my app (App B) and tell it to run a command-line utility that requires a logon. My app would need to pass back exactly what a user would see in a command window so that App B can send additional information. I'm told that the Expect library does this and wanted to know if anyone here has used it and can confirm that. Cheers, Tom Archer - Archer Consulting Group
      "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

      K Offline
      K Offline
      krisko
      wrote on last edited by
      #2

      Expect works wonderfully on Unix and I have used it to be called from Shell Scripts to log on to remote server and execute commands on the server interactively. It is more of a network based tool/library and what you seem to be doing is an IPC kind of application. I doubt if it would work for your scenario. However I developed a similar app as yours where an old command line program was controlled via an MFC app. If you are trying to do the same, then there is a MSDN article that talks about how to do this and I found my solution based on that. I cant remember the title as it was several years ago. If you really need it, let me know and I will it dig it up. Good Luck.

      T 1 Reply Last reply
      0
      • K krisko

        Expect works wonderfully on Unix and I have used it to be called from Shell Scripts to log on to remote server and execute commands on the server interactively. It is more of a network based tool/library and what you seem to be doing is an IPC kind of application. I doubt if it would work for your scenario. However I developed a similar app as yours where an old command line program was controlled via an MFC app. If you are trying to do the same, then there is a MSDN article that talks about how to do this and I found my solution based on that. I cant remember the title as it was several years ago. If you really need it, let me know and I will it dig it up. Good Luck.

        T Offline
        T Offline
        Tom Archer
        wrote on last edited by
        #3

        [krisko] Expect works wonderfully on Unix and I have used it to be called from Shell Scripts to log on to remote server and execute commands on the server interactively. [Tom] Yep. The Unix guys on a current job were the ones that recommended me looking at it. However, they're not Windows guys - hence my reason for being on the project :) - so they weren't sure if it would work from my code. [krisko] It is more of a network based tool/library and what you seem to be doing is an IPC kind of application. [Tom] In a nutshell. The Unix client will send my app (a Windows Service) a request to run a command-line program. I need to report back to the client what's transpiring with the request - whether the prog completed, if I'm back at the prompt, what's on the screen, etc. Does this sound like Expect will work or your code or the MSDN article? And I **badly** need it :) I'm not a rich man, but can send you some books :) Cheers, Tom Archer - Archer Consulting Group
        "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

        K 1 Reply Last reply
        0
        • T Tom Archer

          [krisko] Expect works wonderfully on Unix and I have used it to be called from Shell Scripts to log on to remote server and execute commands on the server interactively. [Tom] Yep. The Unix guys on a current job were the ones that recommended me looking at it. However, they're not Windows guys - hence my reason for being on the project :) - so they weren't sure if it would work from my code. [krisko] It is more of a network based tool/library and what you seem to be doing is an IPC kind of application. [Tom] In a nutshell. The Unix client will send my app (a Windows Service) a request to run a command-line program. I need to report back to the client what's transpiring with the request - whether the prog completed, if I'm back at the prompt, what's on the screen, etc. Does this sound like Expect will work or your code or the MSDN article? And I **badly** need it :) I'm not a rich man, but can send you some books :) Cheers, Tom Archer - Archer Consulting Group
          "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

          K Offline
          K Offline
          krisko
          wrote on last edited by
          #4

          If it is a Unix client (assuming C/C++/Perl/Shell Script), it should be easy to use the Expect API within the client program itself to invoke a telnet session to a Windows Server. However this assumes that the program(yours) running on the Windows server should be a command line program and can be executed via a telnet session on the Windows Server, then Expect would be a good bet. However if it has to go through the Windows Service then I think you will have to spawn a child process and control its Read/Write handles from your service and finally return the output to the Unix client. I am assuming the communication b/w your Windows Service and the Unix Client is Sockets. A quick search yielded this and the idea I used is the pretty much the same for my project

          K T 2 Replies Last reply
          0
          • K krisko

            If it is a Unix client (assuming C/C++/Perl/Shell Script), it should be easy to use the Expect API within the client program itself to invoke a telnet session to a Windows Server. However this assumes that the program(yours) running on the Windows server should be a command line program and can be executed via a telnet session on the Windows Server, then Expect would be a good bet. However if it has to go through the Windows Service then I think you will have to spawn a child process and control its Read/Write handles from your service and finally return the output to the Unix client. I am assuming the communication b/w your Windows Service and the Unix Client is Sockets. A quick search yielded this and the idea I used is the pretty much the same for my project

            K Offline
            K Offline
            krisko
            wrote on last edited by
            #5

            Oops there was a formatting error. Here is the link once again http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating\_a\_child\_process\_with\_redirected\_input\_and\_output.asp

            J 1 Reply Last reply
            0
            • T Tom Archer

              Has anyone used this library in order to control a command prompt from their application? I need to find a tool that will enable my application to run a command that is passed from another application. The trick is that the command may be something that needs additional input. For example, App A could call my app (App B) and tell it to run a command-line utility that requires a logon. My app would need to pass back exactly what a user would see in a command window so that App B can send additional information. I'm told that the Expect library does this and wanted to know if anyone here has used it and can confirm that. Cheers, Tom Archer - Archer Consulting Group
              "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

              T Offline
              T Offline
              trelliot
              wrote on last edited by
              #6

              [, char *envp[ ] ] ] ); The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example. Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

              R N F T 4 Replies Last reply
              0
              • T trelliot

                [, char *envp[ ] ] ] ); The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example. Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

                R Offline
                R Offline
                Ryan Binns
                wrote on last edited by
                #7

                WTF? :wtf:

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                T 1 Reply Last reply
                0
                • R Ryan Binns

                  WTF? :wtf:

                  Ryan

                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                  T Offline
                  T Offline
                  trelliot
                  wrote on last edited by
                  #8

                  Any C (C++) programme accepts command line arguements - that's the 'argv, argc' in main() - what you do with them is up to you...

                  R 1 Reply Last reply
                  0
                  • T trelliot

                    Any C (C++) programme accepts command line arguements - that's the 'argv, argc' in main() - what you do with them is up to you...

                    R Offline
                    R Offline
                    Ryan Binns
                    wrote on last edited by
                    #9

                    I know that, but WTF did that have to do with his question?

                    Ryan

                    "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                    T 1 Reply Last reply
                    0
                    • R Ryan Binns

                      I know that, but WTF did that have to do with his question?

                      Ryan

                      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                      T Offline
                      T Offline
                      trelliot
                      wrote on last edited by
                      #10

                      Easy - either Archer rewrites the command interpreter, adds a commandline intercept (alias) or renames the 'A' programme so 'he or she' can intercept the command and supply appropriate args

                      1 Reply Last reply
                      0
                      • T trelliot

                        [, char *envp[ ] ] ] ); The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example. Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

                        N Offline
                        N Offline
                        Nish Nishant
                        wrote on last edited by
                        #11

                        trelliot wrote: A special function called main is the starting point of execution for all C and C++ programs. The main function is not predefined by the compiler; rather, it must be supplied in the program text. The declaration syntax for main is: [...snipped...][...snipped...][...snipped...] as void, you must use the exit function. :wtf: Why explain this to the guy who wrote Visual C++ Bible?

                        C 1 Reply Last reply
                        0
                        • T trelliot

                          [, char *envp[ ] ] ] ); The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example. Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

                          F Offline
                          F Offline
                          fakefur
                          wrote on last edited by
                          #12

                          :wtf:

                          1 Reply Last reply
                          0
                          • K krisko

                            Oops there was a formatting error. Here is the link once again http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating\_a\_child\_process\_with\_redirected\_input\_and\_output.asp

                            J Offline
                            J Offline
                            Jorgen Sigvardsson
                            wrote on last edited by
                            #13

                            click click[^] -- An eye for an eye will only make the world blind.

                            1 Reply Last reply
                            0
                            • N Nish Nishant

                              trelliot wrote: A special function called main is the starting point of execution for all C and C++ programs. The main function is not predefined by the compiler; rather, it must be supplied in the program text. The declaration syntax for main is: [...snipped...][...snipped...][...snipped...] as void, you must use the exit function. :wtf: Why explain this to the guy who wrote Visual C++ Bible?

                              C Offline
                              C Offline
                              Colin Angus Mackay
                              wrote on last edited by
                              #14

                              Nishant Sivakumar wrote: Why explain this to the guy who wrote Visual C++ Bible? I thought it was rather funny.


                              My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                              V 1 Reply Last reply
                              0
                              • C Colin Angus Mackay

                                Nishant Sivakumar wrote: Why explain this to the guy who wrote Visual C++ Bible? I thought it was rather funny.


                                My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                                V Offline
                                V Offline
                                Vikram A Punathambekar
                                wrote on last edited by
                                #15

                                Colin Angus Mackay wrote: I thought it was rather funny. Me too. :-D I was actually visualizing Tom's face as he read the post (or the email). Vikram.


                                http://www.geocities.com/vpunathambekar "It's like hitting water with your fist. There's all sorts of motion and noise at impact, and no impression left whatsoever shortly thereafter." — gantww.

                                T 1 Reply Last reply
                                0
                                • V Vikram A Punathambekar

                                  Colin Angus Mackay wrote: I thought it was rather funny. Me too. :-D I was actually visualizing Tom's face as he read the post (or the email). Vikram.


                                  http://www.geocities.com/vpunathambekar "It's like hitting water with your fist. There's all sorts of motion and noise at impact, and no impression left whatsoever shortly thereafter." — gantww.

                                  T Offline
                                  T Offline
                                  Tom Archer
                                  wrote on last edited by
                                  #16

                                  :-D I was just like "Oooooo kay" I just figured he/she didn't understand the question or was joking around with me. Cheers, Tom Archer - Archer Consulting Group
                                  "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

                                  1 Reply Last reply
                                  0
                                  • T trelliot

                                    [, char *envp[ ] ] ] ); The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example. Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

                                    T Offline
                                    T Offline
                                    Tom Archer
                                    wrote on last edited by
                                    #17

                                    I appreciate the reply, but that problem isn't one of passing params to a command processor. The problem is interacting with the processor - especially in cases where a command-line app hasn't finished processing, but has requested more info. Cheers, Tom Archer - Archer Consulting Group
                                    "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

                                    1 Reply Last reply
                                    0
                                    • K krisko

                                      If it is a Unix client (assuming C/C++/Perl/Shell Script), it should be easy to use the Expect API within the client program itself to invoke a telnet session to a Windows Server. However this assumes that the program(yours) running on the Windows server should be a command line program and can be executed via a telnet session on the Windows Server, then Expect would be a good bet. However if it has to go through the Windows Service then I think you will have to spawn a child process and control its Read/Write handles from your service and finally return the output to the Unix client. I am assuming the communication b/w your Windows Service and the Unix Client is Sockets. A quick search yielded this and the idea I used is the pretty much the same for my project

                                      T Offline
                                      T Offline
                                      Tom Archer
                                      wrote on last edited by
                                      #18

                                      Sorry. Got sidetracked on other tasks with re: to the same app. The Windows Service must be in control of the entire thing. IOW, the Unix client will send commands to the Service to run. The Service will run the command and send results back to the client. A command might return to the prompt or it might not (as in the case of a command line app such as ftp or telnet) and I'll need to interactively send whatever the app displays back to teh client. Does this sound like Expect for Windows would work for me? Cheers, Tom Archer - Archer Consulting Group
                                      "So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe

                                      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