LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LaunchExecutableEx() with editable bat commands

Solved!
Go to solution

Hi, CVI veterans,

I succeed reading back firmware and EEPROM from a uc with a bat of below code.

 

int status;

char fw_pro_cmd[300]="D:\\data\\read_uc.bat"; 

 

SetWaitCursor(1); 

status=LaunchExecutableEx(fw_pro_cmd,LE_HIDE,&cmd_handle);   

Delay(8); // 8 second is to make sure the cmd is executed surely.

RetireExecutableHandle(cmd_handle);

SetWaitCursor(0);

 

The content of read_uc.bat is

cd d:\Data\

pk2cmd.exe /PPIC18F2320 /GFD:\1.hex >>d:\1.txt

===============================

/GFD:\1.hex means to save the content to D:\1.hex.

I’d like to the hex destination is changeable easier in my next version, instead of fixing it in the bat file. e.g., user can set hex name or full path from user interface.

One approach is to modify the bat file with CVI before using LaunchExecutableEx() , but I don’t prefer it.

Is there a beeter way? Please advise.

 

Thanks.

0 Kudos
Message 1 of 15
(5,921 Views)

Hi,

 

You can easily put your batch file functionality into an executable program.

 

Then you can easily input arguments into your exe.

They appear in the argv input to your main function.

 

Hope this helps,

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 15
(5,914 Views)
Solution
Accepted by topic author labc

You could try passing parameters to the batch file. So your C code would change:

 

    char fw_pro_cmd[300]="D:\\data\\read_uc.bat D:\\1.hex D:\\1.txt"; 

 

and so would your batch file:

 

    pk2cmd.exe /PPIC18F2320 /GF%1 >>%2

 

Obviously you would want to create the string to be sent programatically, but I'm sure you get the general idea.

 

JR

Message 3 of 15
(5,910 Views)

Hi, jr_2005,

The hex path must be pre-defined in the bat file, so it seems that I have to update the bat file if user wants to save the hex to a different path. As I posted previously, I wonder if there are other ways to handle my issue, instead of updating bat file?

==============

/GFD:\1.hex

/G is command, D:\1.hex is path.

 

thanks.

 

 

 

0 Kudos
Message 4 of 15
(5,888 Views)

@labc wrote:

 

The hex path must be pre-defined in the bat file 


Did you try my suggestion? The "%1" and "%2" text strings in the batch file will be replaced by corresponding strings present in the command line, before it is processed by the operating system - this is all pretty standard batch file parameter passing stuff. Try it and see.

 

Is there any other reason that you think this approach would not be suitable? For example, are the files locked down by some audit requirements and so must not be altered?

 

JR

0 Kudos
Message 5 of 15
(5,867 Views)

Hi, jr_2005,

Thanks for your suggestion, and I didn't try for I have no idea about how to apply cmd parameters %1 %2.

I googled a link and realize your advice are pretty good.

Could you please share me some links to study the parameters? Some examples are appreciated.

 

0 Kudos
Message 6 of 15
(5,818 Views)

Hi, who can help me?

Thanks.

0 Kudos
Message 7 of 15
(5,775 Views)

Hi labc, a simple google search returned this page which I consider exhaustive on DOS batch files.

There is nothing different on their usage in CVI: you must simply accomodate in a proper way the string to pass to LaunchExecutable.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 15
(5,757 Views)

Hi, Roberto,

Great! Thank you.

0 Kudos
Message 9 of 15
(5,732 Views)
Some feedback. Parameter %1 accecpts strings without spaces only, which would ignore the characters after the space. Always the strings(a path) I pass to %1 includes several space, so I would not use this method. Anyway, thank you all the same.
0 Kudos
Message 10 of 15
(5,707 Views)