import filename/string into COMSOL executable, from command line?

Please login with a confirmed email address before reporting spam

Does anyone know how to import a filename into a COMSOL executable app? (Parameters can't be strings, AFAIK.) Is there a command to get STRING input from the command window that is calling the executable (like there is in most languages), so I can run my executable from a .bat file?
(Important: I want to do this with an EXECUTABLE, that I've made with the COMSOL compiler, so that running it doesn't require any COMSOL license.) (Important: Yes, I know that one can do this with an executable INTERACTIVELY. Can it be done non-interactively?) (Clarification: My program has about 50 parameters that its users might want to vary, to optimize the design for different purposes. There is no single goal that I can optimize for, so the users have to do that. It isn't practical to make hundreds of versions of the program.)


3 Replies Last Post 25 juin 2024, 13:01 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 5 months ago 19 juin 2024, 19:10 UTC−4

Clarification: I realize that I can make a parameter "CalcNumber", and then have my input files be something like InputFile = "StandardInputPrefix_"+toInteger(CalcNumber); and output files be something like OutputFile = "StandardOutputPrefix_"+toInteger(CalcNumber); with obvious extensions for files that are saving specific results. But that would make it difficult to keep track of various calculations, since all the filenames would differ only by that CalcNumber. I really want my batch file that is calling my executable to specify a file with an arbitrary filename (complete with location) for the file that contains all the needed parameters. And I want that arbitrary filename to be the root for all the output files that get saved after the calculation.

One last thought: I suppose I could have the calling batch file keep renaming files as they are needed and generated. But really? There's not a better way? Please tell me there is a better way!

Clarification: I realize that I can make a parameter "CalcNumber", and then have my input files be something like InputFile = "StandardInputPrefix_"+toInteger(CalcNumber); and output files be something like OutputFile = "StandardOutputPrefix_"+toInteger(CalcNumber); with obvious extensions for files that are saving specific results. But that would make it difficult to keep track of various calculations, since all the filenames would differ only by that CalcNumber. I really want my batch file that is calling my executable to specify a file with an arbitrary filename (complete with location) for the file that contains all the needed parameters. And I want that arbitrary filename to be the root for all the output files that get saved after the calculation. One last thought: I suppose I could have the calling batch file keep renaming files as they are needed and generated. But really? There's not a better way? Please tell me there is a better way!

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 months ago 24 juin 2024, 02:40 UTC−4

Hi David,

Perhaps an Application Argument node could be used here. It provides a poweful way of sending inputs to COMSOL apps (including compiled apps) from the command line. See the documentation for more information.

Best regards, Magnus

Hi David, Perhaps an Application Argument node could be used here. It provides a poweful way of sending inputs to COMSOL apps (including compiled apps) from the command line. See the documentation for more information. Best regards, Magnus

Please login with a confirmed email address before reporting spam

Posted: 5 months ago 25 juin 2024, 13:01 UTC−4
Updated: 5 months ago 25 juin 2024, 13:43 UTC−4

Magnus: App args was the way to go. I could not get it to work for days. In the end, it turned out that the particular version of Windows PowerShell that I have was preventing me from passing full filenames (with : and \ in them) into the app arg. Used just a plain command prompt, and it worked. Kudos to Akhilesh Sasankan for asking about PowerShell.

Magnus: App args was the way to go. I could not get it to work for days. In the end, it turned out that the particular version of Windows PowerShell that I have was preventing me from passing full filenames (with : and \ in them) into the app arg. Used just a plain command prompt, and it worked. Kudos to Akhilesh Sasankan for asking about PowerShell.

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.