Jump to content
Sign in to follow this  
Nighterfighter

Quick help with the Run() function and passing parameters

Recommended Posts

Nighterfighter

Hey everyone, I am writing a script to launch a custom C# application that I developed, and this application accepts parameters from the command line. I know that it works, as I am able to run it from the command line just fine. I can even get it to run with the AutoIt script, using hardcoded values. However I need to pass the command-line arguments as a variable, so they can be changed easily. 

 

Here is what I have, that works perfectly:

Run('"C:\Users\Public\Documents\Merger.exe" "C:\Users\MattBrown\Documents\ProgramTestAllFiles\Def" "C:\Users\MattBrown\Documents\ProgramTestAllFiles\Sql" "C:\Users\MattBrown\Documents\ProgramTestAllFiles\output.xlsx"');

However, those long file paths are cumbersome. I made variables for them, but I can't seem to get the Run command to work with variables. Code below:

Global $DefFileFolder = "C:\Users\MattBrown\Documents\ProgramTestAllFiles\Def";
Global $SqlFileFolder = "C:\Users\MattBrown\Documents\ProgramTestAllFiles\Sql";
Global $OutputFile = "C:\Users\MattBrown\Documents\ProgramTestAllFiles\output.xlsx";
Global $MergerLauncher = "C:\Users\Public\Documents\Merger.exe";

Run('$MergerLauncher $DefFileFolder $SqlFileFolder $OutputFile');

I have tried many variations of that, with different " " or ' ' around the variable names, but I just can't get it to work.

 

Can anyone help me get this to run? I can also use ShellExecute, if that will work. As long as the arguments are passed separately, that will work. (I tried ShellExecute, but it passed all of my parameters as ONE argument, which won't work with my C# application).

 

Thanks!

Share this post


Link to post
Share on other sites
MuffinMan

Try adding a space at the end of each of your variables.

Share this post


Link to post
Share on other sites
Nighterfighter

I just tried that, and it did not work. This is what I tried:

 

Run('$MergerLauncher  $DefFileFolder  $SqlFileFolder  $OutputFile ');

I also tried by putting a "" between each variable and that did not work either.

Share this post


Link to post
Share on other sites
Nighterfighter

If I do this it will launch just the .exe, so i know that my paths are correct:

 

Run($MergerLauncher);

The problem comes when I try and add the other variables, to have their values passed as command line arguments.

Share this post


Link to post
Share on other sites
MuffinMan

Maybe this...

Run('$MergerLauncher & " " & $DefFileFolder & " " & $SqlFileFolder & " " & $OutputFile ');

Share this post


Link to post
Share on other sites
Nighterfighter

That doesn't launch the executable, it just skips over it and nothing happens.

 

HOWEVER, I did get it to work. I concatenated the strings, to make them one long command, and then just Run() it, like below. 

Global $runCommand = $MergerLauncher & " " & $DefFileFolder & " " & $SqlFileFolder & " " & $OutputFile;
Run($runCommand);

And that worked the way I needed it to.

 

Thanks for the help, MuffinMan. 

Share this post


Link to post
Share on other sites
MuffinMan

Cool... Fake it til you make it!  So it sounds like you needed the spaces and to remove the single quotes in your original Run line.

Share this post


Link to post
Share on other sites
Nighterfighter

Yup, I decided to clean that formatting up a bit, and this works the same as what I did:

 

Run($MergerLauncher & " " & $DefFileFolder & " " & $SqlFileFolder & " " & $OutputFile);

 

I'll be going with that, as it is one less variable that needs to be declared and have memory malloc()'d to it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×