I've created a c# based GUI that starts a compiled MATLAB executable on a remote server. I'm trying to read data from the local machine to the executable but I'm getting an invalid filename error (Invalid file identifier. Use fopen to generate a valid file identifier) when referencing the local machine.
I have tested running the executable directly on the remote server and referencing the local machine's data and had success, the problem seems to be having the process initialized from a different environment and then asking the process to refer back to the original environment possibly requiring some sort of login?
The servers and local machine are all connected to our company network so my method of reading the remote data is to reference the machines name as the drive (I.e. replacing c:\ with \\SERVER1\).
The code I've used to initialize the remote process is:
connectionOptions connOptions = new ConnectionOptions();
connOptions.Username = textBox4.Text;
connOptions.Password = textBox3.Text;
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope("\\\\SERVER01\\ROOT\\CIMV2", connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
object[] methodArgs = { "\\\\SERVER01\\folder1\\Data\\Files\\matlabProgram.exe " + params1.ToString() };
object result = processClass.InvokeMethod("Create", methodArgs);
The set of parameters passed to the program in params1 contains filepaths which reference files and folders on the local machine (i.e. \\LOCAL01\...).
Running the GUI from within the server using the usual process start method works:
Process p = null;
p = System.Diagnostics.Process.Start("\\\\SERVER01\\folder1\\Data\\Files\\matlabProgram.exe ", params1);
The MATLAB code throwing the error is:
f = fopen('\\LOCAL01\folder1\Data\Files\statuslog.txt','w');
fprintf(f,'%s','Sup');
I'd really appreciate any insight into this issue being a real beginner with c# programming. Thanks!
Update: So it turns out according to @Dennis in his answer for How to execute a command in a remote computer? that you cannot reference paths that are not local to the remote machine. Is there perhaps a way around this besides having to copy the required files over to the remote machine?