Execute m file at startup - call

I have a MATLAB m file, which I now manually execute after every startup of MATLAB. The file is located in a directory defined by an environmental variable. For example, if the file is start.m in directory D:\Dir then the environmental variable is FILE_PATH = "D:\Dir" and the full file path is %FILE_PATH%/start.m.
What I want to do is call this m file every time MATLAB starts, from a batch file. How can I do this?

Read this manual page. You could use the startup.m file for this.

Related

Batch export in SAS for spk file

I need to export/import my spk file via windows Batch script.
For which I have been referring this document
But this document does not mention how to save the file (I mean with which extension .bat or .sas)
My command:
ExportPackage -profile "SAS_MW_TEST" -package "F:\mypath\Package4.spk" -objects "/_Applications/_05_MW/_01_SAS_MW/_20_Processes/savedesk(Folder)" -subprop -types "Condition,BusinessRuleFlow,ExternalFile,Cube,SearchFolder,Table,GeneratedTransform,OLAPSchema,InformationMap.OLAP,Measure,Column,Job.CubeBuild,Action,Library,MiningResults,DeployedJob,CalculatedMeasure,Hierarchy,InformationMap.Relational,RootFolder,Prompt,Document,ConditionActionSet,DecisionLogic,Dimension,Note,StoredProcess,PromptGroup,Job,OrchestrationJob,MessageQueue,Service.SoapGenerated,Level,SharedDimension,DeployedFlow"
ExportPackage is an executable program that you can run out of a batch file.
Use Notepad or any other text editor (which includes any SAS code editor), place the ExportPackage program command in the editor and use the File/Save As feature to save the file as something like myPackageExporter.bat
If the items in the package are say stored processes whose metadata says the source code is in an file system folder (aka source code repository), you will probably also want to zip up the folder.
This macro can help you prepare the batch script, ready for export: https://core.sasjs.io/mm__spkexport_8sas.html

Open file without Filename with lua skript

Good evening,
I am currently working on a programm that takes information from a file into a Database, for testing purposes I used to open Testfiles in the classical way via IO:
function reader (file, delimeter)
local f = io.open(file)
for line in f:lines() do
lines[count] = splitty(line, delimeter)
count = count + 1;
end
end
(this part also containes the first part of a splitter)
But in the actual environment, the database programm imediatly moves the file in another directory with a name change to, for example this:
$30$15$2016$09$26$13$27$24$444Z$.Pal.INV.csv
Now I know the directory but I can't really predict the name, so I wanted to know if there might be a way to open files without knowing their name.
(and delete them after reading them)
I had ideas to use a modified link:
local inputFile = "D:\\Directory\\(*all)"
but it failed.
Other aviable information:
The system is until now only planned on Windows PCs.
The directory will always only contain the one file that is to ready, no other files.
You can use the lfs.dir iterator from LuaFileSystem to iterate through the contents of the directory. A small example:
local lfs = require("lfs")
local path = "D:\\Directory\\" -- Your directory path goes here.
for filename in lfs.dir(path) do
print(filename) -- Work with filename, i will just print it
end
If you keep a record of the files you will be able to know which one is the new one. If it is only one file, then it will be easier, you can just check the extension with a string function. From what i remember the iterator includes .. and .. lfs documentation can be found here.
-- directory name and file name should consist of ASCII-7-bit characters only
local dir = [[C:\Temp\New Folder]]
local file = io.popen('dir /b/s/a-d "'..dir..'" 2>nul:'):read"*a":match"%C+"
if not file then
error"No files in this directory"
end
-- print the file name of first file in the directory
print(file) --> C:\Temp\New Folder\New Text Document.txt

Set paths in C program for executing external programs

I wrote my program in C which includes calling a bash script and another external program from it (all of them located in the same directory as my C program). I set the path of the executing files strict so like:
char *path_for_the_script = "location/of/script.sh";
and compile my program.c without any special arguments..
Now I wonder how can I manage that this path gets set by the program, so that someone else could use it from his computer without changing the paths manually?
Load the path from a environment variable (also add a fallback or failure path if the variable is not set) and have your program being launched through a wrapper script, which the user can adjust.
Example
in yourprogram.c
char const * const path_for_the_script = gentenv("YOURPROGRAM_SCRIPT_PATH");
the programlauncher.sh
#!/bin/sh
export YOURPROGRAM_SCRIPT_PATH="..."
exec yourprogram $#
Instead of setting the path in your code, create a text file in the same directory and fetch the path information from the txt file. Thus anyone can modify the text file with required path and execute the program, with out any code modification.
create a file in same directory as source.txt
vi source.txt
location/of/script.sh
In your program, use file open operation and access the file contents and assign to path_for_the_script char buffer. This method works only when all the users share the same computer.

How to write batch file which use the name of one file as part of the name of another file

I have some java executable program initialized from cmd. My problem is as following: I would like to read all files from some directory. Next, I would like to run the program as many times as many files I have in my folder. The required inputs are the path to the file with data and the name of the file where the results will be written. Now my question is, how can I write a simple batch file which will do it for me?
For example:
I have a list of files in my folder
file_1.xls
file_2.xls
file_3.xls
I want to run a loop and for each file initialize line specified below:
java -jar -Xmx1000M Program.jar pathToInputFile PathToOutputfile
For example for file file_1.xls I want to write the result to the file with the same name but different extension and at the begining of this file add some constant prefix. In case of file_1.xls the results I would like to write as Output_file_1.txt
for file_2.xls -> Output_file_2.txt
for file_3.xls -> Output_file_3.txt
and so on...
Can anyone help me?
pushd "c:\excel_files"
for %%F in (*.xls) do (
java -jar -Xmx1000M Program.jar "%%~nxF" "Output_%%~nF.txt"
)
Though I'll recommend you to use -classpath and direct call of the entry point class instead of direct call of the .jar .

Where "io.open" saves the file if it doesn't exist yet?

I could find out here, how can I create a new file with pure Lua code. The next snippet should do it theoretically:
file = io.open("test.txt", "w")
file:write("Hello World")
file:close()
However, I can't find the created file in the folder of the source code file. Where does it save the file - if it even creates a new one?
If not, what's the way of doing it?
It will use the processes current working directory (CWD) which is going to wherever your shell/environment was when you ran the script.

Resources