NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing arguments to exe using the Argument Expression

Hello,

 

I need some help regarding the way in which the Argument Expression field, in the Call Settings tab of a CallExecutable step, should be set.

Using the cmd.exe utility I can execute the following operation:

C:\Program Files (x86)\.......>Application.exe -input "Path file1...." -format s19 -output "Path file2...."

In the TestStand step I have selected the Application.exe file path.

Next I have tried to set the Argument Expression field in different ways. The last version was:

"/k -input\"E:\\Path file1....\"/k -format s19 -output\"E:\\Path file2....\""

But it does not work.

 

Could you advise me? Thank you, have a nice day.

0 Kudos
Message 1 of 6
(6,312 Views)

This Application.exe, does it understand what /k means?

It seems like when you originally use it from cmd.exe you don't use the /k, the /k is when using a command with cmd.exe, not within your application.exe. Remove all instances of that and see what happens.

 

Or another way to say what I'm saying. Take your original command

C:\Program Files (x86)\.......>Application.exe [-input "Path file1...." -format s19 -output "Path file2...."]

And everything I put in square brackets, copy and paste that into Argument Expression

 

 

Message 2 of 6
(6,270 Views)

Dear ShockHouse,

 

Thank you for the reply.

In the Argument Expression I have placed the following input:

-input "E:\\Test\\Source.mot" -format s19 -output "E:\\Test\\Destination.frb". I have also attached an image of the screen.

I am getting an error: Rule : Expressions must evaluate to a value of the expected type

I feel that the Argument Expression must be only a string inside the "...".

If I set it as: "-input E:\\Test\\Source.mot -format s19 -output E:\\Test\\Destination.frb" there is no error but the *.exe does nothing.

 

If you have other ideas please let me know. Thank you.

 

 

 

 

 

 

0 Kudos
Message 3 of 6
(6,246 Views)

Is there anything stopping you from just using cmd prompt then instead of calling straight to your application?

 

If you already know that using the command prompt, and then typing "C:\Program Files (x86)\.....>Application.exe...." works, you can just use that method.

image.png

Just change your file pathname to point to cmd.exe (so its the command prompt), and then put in what you normally would for the argument. And don't forget that the paths will need quotations around them if they have a space somewhere. Since this is placing a string into cmd.exe you want those quotations to be carried over as well. So you need to do syntax like \"" for a quotation. Because just doing this " somewhere in there, it will get removed. I put an example of one I do that works. I wanted quotations around the paths.

image.png

 

0 Kudos
Message 4 of 6
(6,229 Views)

Dear ShockHouse,

 

I have created a *.bat file with all the needed commands and I have chosen to call that file from TestStand. It works. So this may be a solution. However, if you need to change the source and destination parameters, you will still need some programmatic file editing before the actual call. It can be done but I do not believe this is the most elegant solution. What do you think?

 

I was getting frustrated with the setup for the cmd.exe. As you indicated, I have chosen the cmd.exe as the target executable. Inside the argument expression I placed the following:

 

"/C C:\Program Files (x86)\.....>MyApp.exe -input \""+ Locals.Source_File+"\" -format s19 -output\""+ Locals.Destination_File+"\""

 

The local variables are just strings initialized to the values of my file paths. For example: E:\file1.txt

 

Now, if I check the expression using the Check Expression for Errors option it says that all is fine. However, if I check this using the Sequence Analyzer, it will indicate an error: Rule : All escape sequences used in expressions must be valid
Description : The sequence analyzer checks expressions for valid escape sequences. Improperly escaping
paths usually leads to using invalid escape sequences, which are rarely intended

 

So I modified the argument as:

 

"/C C:\\Program Files (x86)\\.....>MyApp.exe -input \""+ Locals.Source_File+"\" -format s19 -output\""+ Locals.Destination_File+"\""

 

It executes but does not produce any results.

In conclusion, if you still have the patience, please check to see if my argument needs a change. I believe I am missing something. Overall, I believe it can be more elegant just to modify the local variables and keep the executable call unchanged.

 

Thank you for all your efforts. Have a nice day.

 

 

 

0 Kudos
Message 5 of 6
(6,208 Views)

By executes do you mean the program executes?

 

Honestly to me at this point it looks like the executable is not being called since there is a space in the path, cmd.exe won't know what to do.

"/C C:\\Program Files (x86)\\.....>MyApp.exe -input \""+ Locals.Source_File+"\" -format s19 -output\""+ Locals.Destination_File+"\""

I would suggest turning that into this

"/C \""C:\\Program Files (x86)\\.....>MyApp.exe"\" -input \""+ Locals.Source_File+"\" -format s19 -output\""+ Locals.Destination_File+"\""

 

You can see if I put the first one into cmd.exe the exeutable never launches because of the path (the space right after Program. But if I put the path to the executable in quotes as well it actually launches. (The red lines are just my name so I got rid of them)

image.png

 

Another thing you can try to do is see what cmd.exe is actually outputting. If you click on the Standard Output/Error, put the Output and Error into a local variable so you can see what is being returned.

 

0 Kudos
Message 6 of 6
(6,196 Views)