I've learnt a pretty sweet Windows command line trick today by looking into someone's code at work, so I'll share it here.
It's clear that if we want to pass the contents of a file as standard input to a program all we need is:
myProgram.exe < myFile.txt
But what if we want to pass the content of that file as a parameter to the program? For example you have a program that encrypts a password that you pass as parameter, and you have that password already in a file. The solution is assigning the content of that file to an environment variable, and then passing the value of the environment variable as parameter to the program, I mean:
set /P myVar=<myPasswordFile.txtencrypt.exe %myVar%
In Linux, as explained here, the thing is more simple:
./encrypt `cat myPasswordFile.txt`
No comments:
Post a Comment