Link to home
Start Free TrialLog in
Avatar of LesterJebson
LesterJebsonFlag for United States of America

asked on

Can I pass command line arguments from inside a file?

Is it possible to pass command line arguments to the command prompt from inside a text file?  

I have several scheduled tasks in Windows Task Scheduler that myprogram.exe with the arguments "pswd=mypassword mypgmparm=thisvalue".  Is it possible to place the argments inside a text file so I don't have to modify every task whenever I want to change the command line parameter the program uses?
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's very doable.

However, I would strongly recommend switching to Windows Powershell for scripting, instead of Batch.  Batch is really out-dated, as opposed to Powershell, which was designed for sysadmins, and contains numerous incredibly powerful features that make scripting a breeze.
nick2253,

totally agreed about powershell, stuff that is hard in batch or neededing VBScript bits or other utils etc. natively BUT if just talking about running a few exe's with command line options probably good idea to do this.

If you want the password semi-hidden too you could place them in an alternative data stream within the text file so opened it notepad it just looks like "This is a text file", e.g. see this technique:

http://scripts.dragon-it.co.uk/links/batch-password1
http://scripts.dragon-it.co.uk/links/batch-password2

That doesn't have to be in the batch file itself (which is why we used %0) but any other file.  Still available to find it for anyone who knows how but a bit better than a plain text file.

Steve
Hiding passwords in other data streams is highly insecure.  Worse, it gives the impression of security where none is to be had.

If you really need your password to be secure, you need to encrypt it, and use an appropriate program to process on it.

Lastly, there's no reason to use batch anymore.  For the use cases that you provide, a Powershell Script is at worst no more work than a batch file.  I can't think of a single case where a batch file would be less work than a powershell script.
Avatar of Bill Prew
Bill Prew

You might want to look at this prior question as well, it had some interesting discussion about this topic.

https://www.experts-exchange.com/questions/25000620/read-in-a-file-in-batch-script.html

~bp
Avatar of LesterJebson

ASKER

This works!  Thank you.  

I wish I could've done this in Powershell instead of a .bat file.  The thing that prevented that was we do not have rights to run Powershell scripts in batch mode on that computer.