using ExecuteScriptText

Hi,

I am trying to write an Igor function which: (i) reads some input from Igor, (ii) launches an external program (a plain DOS-type application with no GUI) which reads the input generated by Igor (from a file) and produces an output file (containing a trace/two columns of real numbers), and (iii) uses Igor to read the output of this external program and plot it on some existing or new window. 

Toward this aim, I wrote the function listed below which incorporates all these elements but which unfortunately does not work. In this example, in the first step (i), Igor reads a number from a prompt and saves it in the "input_ba19.txt" file. In the second step (ii), the Igor starts the program trialprog.exe which is supposed to read the number from the input file, multiply it by some value, and save the result in a (new) output file, output_ba19.txt. In the last step, (iii), Igor is supposed to read the result and in, this case, print it out.

This code fails in step two, (ii), while running the "ExecuteScriptText" command because the test application "trialprogram.exe" cannot find the input file. From what I understand this is not surprising because Igor runs this application not in the folder where it is located but rather it redirects its input/output to a selected folder which, according to the documentation should be the "Igor Pro User Files". However, in my case input/output is directed to: C:\Users\CurrentUser\AppData\Local\VirtualStore\Program Files\WaveMetrics\Igor Pro 9 Folder\IgorBinaries_x64.

In this example I had the test application and its input file in the "C:\tryEST" folder. I have tried different locations and the specific folder used is not the problem.The actual location is important only in the sense that, to keep track of it, I would like to hard-code it in the final function. I have also tried different arguments and options for the ExecuteSriptText command for example, without including the input file name, and this did not solve the issue I encountered. I have also tried using a batch file with the the ExecuteSriptText  command, an relevant example is included below, but that did not work either.

Finally, as I tried to work my way around this problem I have also looked at the ExecuteDOSCommand included in the help file and listed on the exchange forum. This function fails to run as advertised but the reason for this failure is that the dosCommand string it produces and places into the batchFilePath batch file which is subsequently submitted to ExecuteSriptText  is truncated. Specifically, in this case the string produced is   "C: ryEST rialprog.exe > "C:\Users\CurrentUser\Documents\WaveMetrics\Igor Pro 9 User Files\igorBatchOutput.txt". Please note the missing "t"s and ":" in this string.

I would appreciate any help or advice that you can provide which could help me solve this issue.

Thank you!

 

 

function use_external_program()


 variable input, refin, output

   Prompt input, "Read input"
 DoPrompt "Read point input", input
 
 string fileName = "input_ba19.txt", buffer
 newpath/o filedir "C:tryEST"
 
 open/p=filedir refin as filename
  fprintf refin, "%d", input
 close refin
 
 ExecuteScriptText/b "C:\\tryEST\\trialprog.EXE input_ba19.txt"
 
 print s_value
 
   filename = "output_ba19.txt"
 
 open/r/p=filedir refin as filename
     freadline refin, buffer
     sscanf  buffer,"%d", output
 close refin
 
  print output

end function

 

contents of the trialprog.bat file used to test ExecuteScriptText command

ECHO "program start"
START "TRIAL PROG" C:\tryEST\trialprog.EXE
ECHO "program exit"
EXIT

 

 

sprintf interprets \t as a tab character.

execute DisplayHelpTopic "Escape Sequences in Strings"

tip:

this may not be relevant for you, but if you need to overwrite or clean up the batch file you may have make it explicitly set its own attributes:

fprintf refnum_bat, "attrib -R %0\r\n" // make THIS batch file writeable
fprintf refnum_bat, "exit\r\n"

 

Shouldn't this line reference the .bat not the .exe if you are using a batch file - I'm not clear if you are or not?

// should shis
ExecuteScriptText/b "C:\\tryEST\\trialprog.EXE input_ba19.txt"
// not be this
ExecuteScriptText/b "C:\\tryEST\\trialprog.bat input_ba19.txt"

I'm not sure a .bat file is even needed for this and you could use ExecuteScriptText directly. You might need to open the shell if they are DOS executables, and you will likely need to provide full windows paths to the input .txt file if the executable isn't in the same folder. e.g.

ExecuteScriptText /B /Z "cmd.exe /C cd C:\\some\\path\\ && trialprog.exe C:\\full\path\\to\\input_ba19.txt"

On odd occations the .exe might even be required to have the same path as the input file too which is no big deal as you can copy it from somewhere safe using igor or a batch file and delete the copy when you're done.

Hi Cpr,

 The arguments you listed do the trick. They work beautifully, thank you! I would have never guessed this syntax, particularly to use the of full path for the input file and of "&&" between the path and the executable. Regarding your first comment, prior to posting my message, I have tried both the *.exe and the *.bat files with the idea that the *bat would restore the path to the program. Regardless, I don't have to play with it anymore (at least for now).

Have a nice day!

S

 

In reply to by aclight

Hi ACLight,

Thank you for your reply. I did come across your code. I tested it and it works well for what it is advertised. However, I have (had) a hard time to adapt it for my purpose. I am convinced that this is due to my inexperience with Igor. Perhaps you could specify where and how the call to the external application using ExecuteScriptText should be implemented.

Best,

S