The MASM Forum

General => The Campus => Topic started by: PatrickDS on July 17, 2020, 05:54:24 AM

Title: Giving a program arguments over the command line
Post by: PatrickDS on July 17, 2020, 05:54:24 AM
I did loads of research on this topic but never found anything that matches my problem.
I want to write a program that can be started over the windows command line like this:

program.exe "a string as input"


The program then uses the string to do some stuff with it and should output just one line of text.

Example:

>program.exe "a string as input"
output
>


It should not open its own window!
It would be awesome if somebody could show me how to do that. Thank you! :biggrin:
I also wanted to thank you for your warm welcome in this forum!  :smiley:
Title: Re: Giving a program arguments over the command line
Post by: jj2007 on July 17, 2020, 06:17:27 AM
include \masm32\include\masm32rt.inc
.code
start:
  print cmd$(1)
  exit
end start
Title: Re: Giving a program arguments over the command line
Post by: Vortex on July 17, 2020, 06:18:30 AM
Hello,

You can study the following functions, they are the members of masm32.lib :

\masm32\help\masm32.chm -> Command Line Procedures

Command Line Procedures

ArgCL
ArgClC
GetCL
getcl_ex
Title: Re: Giving a program arguments over the command line
Post by: PatrickDS on July 17, 2020, 06:26:58 AM
Thank you!  :thup:
Title: Re: Giving a program arguments over the command line
Post by: jj2007 on July 17, 2020, 06:32:41 AM
There is an interesting Windows API function, too: CommandLineToArgvW (https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw)