Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm kind of new in powershell, so please pardon me..
Let's say we want to create a simple .exe file which can be executed in powershell..
Let's say the program is basically can do:
if "a" is pressed, it will print the string "a is being pressed" on a new line.
if "b" is pressed, it will print the string "b is being pressed" on a new line.
How to do so?
How to make the .exe file for that?
and how to open it with powershell?

Please someone explain to me start from the beginning if it is possible.
Great many thanks for all the folks here.. :)
Posted

1 solution

You can do it, of course, but your whole script would become "interactive" (waiting for user input) which would make it pretty much useless as such. In this case, normal windowed application could be better, as the console application with interactive input would defeat the purpose of the batch.

In professional practice, there are many programs written for console mode, and nearly all of them are purely or optionally non-interactive, that is, using only the console output and no interactive input at all. Instead, input data is passed through few command line parameters; if you need to input more data, especially non-text data, one or more of the parameters could be used to pass a file name.

This approach would make your application perfectly suitable for Power Shell or regular *.BAT batches.

You would need a good technique to parse command line parameters. I would offer my easy-to-use but feature-rich library: Enumeration-based Command Line Utility[^].

It is provided in full source code and is good for maintenance which is clearly shown in a set of usage code samples.

—SA
 
Share this answer
 
v4
Comments
fjdiewornncalwe 15-Feb-12 13:51pm    
Agreed.
Sergey Alexandrovich Kryukov 15-Feb-12 13:56pm    
Thank you, Marcus.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900