Search notes:

Programs and scripts that show command line arguments

Every once in a while, I need to know what arguments are passed to a program or a script. In order not to always create such scripts and programs from scratch, I continue to put these programs and scripts here.

prog.c

prog.c is the C version:
#include <stdio.h>

int main(int argc, char* argv[]) {
   printf("%s has received %d arguments:\n", argv[0], argc-1);
   for (int i = 1; i<argc; i++) {
      printf(">%s<\n", argv[i]);
   }
}
Github repository show-command-line-arguments, path: /prog.c

script.ps1

scipt.ps1 is the PowerShell version:
write-host "$($myInvocation.myCommand.path)\$($myInvocation.myCommand.name) has recevied $($args.count) arguments:"

$args | foreach-object {
  "  $_"
}
Github repository show-command-line-arguments, path: /script.ps1

proc.cs

prog.cs is the C# variant:
using System;

public class ShowArgs {

   static void Main(String[] argv) {
      Console.WriteLine($"{System.AppDomain.CurrentDomain.FriendlyName}: argument count is {argv.Length}:");
      foreach (var arg in argv) {
         Console.WriteLine("  " + arg);
      }
   }
}
Github repository show-command-line-arguments, path: /prog.cs

See also

The Github repository for these scripts is here.
Showing command line arguments when executing a batch file and an exe.

Index