1

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?

Community
  • 1
  • 1
  • It is worth giving a minimal piece of code that demonstrates the problem, and your error message (plus maybe any relevant log messages from server). Your connection technology is likely to be important (e.g. are you ssh-ing in and running command line, or accessing via a purpose-built library/API for remote control). Plus actual code and error messages will get you a better match to someone who may know about your specific problem. – Neil Slater Jan 16 '15 at 11:59
  • Thanks Neil, will make the necessary edits. I'll try add the code snippets a little later, unfortunately having a bit of a problem logging onto this website from my laptop. – user2848074 Jan 16 '15 at 12:44
  • 1
    Do you have write permission on this folder (from your local machine) ? When you start the matlab `exe` from your local machine, the program starts with your local credentials. As debugging steps, try opening the file in read only mode, or just check for its existence in the matlab exe. If that works you'll know it's a write permission issue. – Hoki Jan 16 '15 at 15:35
  • Thanks @Hoki. I'm not sure it's a write permission issue since I'm able to write to the local machine from other environments using different credentials (the folder has been set up to be shared to everyone on the network for the duration of the testing). I tested this out by writing to a text file on the local machine from another desktop from Matlab directly and then by running a Matlab compiled script on the server which writes to a local text file. The problem creeps in when running a program on the local which launches the script on the server which is then unable to write to the local. – user2848074 Jan 21 '15 at 09:16
  • @user2848074. In this last configuration which fail, what happen if you try to open the file in `read only` mode ? – Hoki Jan 21 '15 at 09:57
  • @Hoki, when I set the file to "read-only" and use the fopen(...,'r') command I still receive the "Invalid file identifier" error. – user2848074 Jan 21 '15 at 10:14
  • 1
    then try to use [`uigetfile`](http://mathworks.com/help/matlab/ref/uigetfile.html) first instead of a hard coded path. This will have the user navigate to the folder manually. I think that should prompt you if you need to enter extra credentials. – Hoki Jan 21 '15 at 10:43
  • Good idea, but I'm not sure I can use uigetfile since the Matlab process is launched remotely so you'd have to somehow get the ui to appear on the local machine or view it on the server. Both of which I'm not certain how to do (even when logged into the server using the credentials used to launch the process the graphical elements are not present)... – user2848074 Jan 21 '15 at 11:19

0 Answers0