2

I want to use javaaddpath with different path to be added on my linux and window computer.

However, I want it to be true dynamic allocation. In other words, user can define his/her own Path_Str = ' ....../ParforProgMonv2/java' and pass it at this step: pctRunOnAll javaaddpath (Path_Str)

After opening matlab pool, I want to do something like this:

if strcmp(MonitorProcess, 'Yes')
    %add this line for progress monitor
    pctRunOnAll javaaddpath ('/home/dkumar/ParforProgMonv2/java')
end

However, rather than fixed path '/home/dkumar/ParforProgMonv2/java', I would like to include dynamic path chosen between

'/home/dkumar/ParforProgMonv2/java' or 'C:/Users/DK_GS/ParforProgMonv2/java'

depending on whether it's my window computer or linux.

I tried to follow this solution using ClassPathHacker.java; however, did not understand it.

Some help would be appreciated.

Community
  • 1
  • 1
Garima Singh
  • 1,410
  • 5
  • 22
  • 46

1 Answers1

3

Would something like this work?

searchpath = 'ParforProgMonv2/java'; % Directory to search for

if strcmp(MonitorProcess, 'Yes')
    switch computer
        case {'PCWIN', 'PCWIN64'}
            % 32 or 64 bit Windows
            % Use the system command to return all directories found on the machine
            % that match your search directory. Use a regex to clean up the list
            [~, cmdout] = system(['dir /s/b/AD | find "' searchstr '"');
            allpaths = regexp(cmdout, '(.:\\[\w\-\\. ]+\w+(?=\s))', 'match'); % Split directory names, 1st cell should be the top level
            pctRunOnAll javaaddpath (allpaths{1})
        case 'GLNXA64'
            % Linux
            pctRunOnAll javaaddpath ('/home/dkumar/ParforProgMonv2/java')
        otherwise
            % Insert error handling here
    end
end

Where computer returns a string specifying the computer type that is currently running.

EDIT: Per your comment I would recommend adding in a method to search for your filepath and return a string. I've added a sample for Windows; I'm not familiar enough with Linux to translate properly.

sco1
  • 12,154
  • 5
  • 26
  • 48
  • Though it would work, I want it to be true dynamic allocation. In other words, user can define his/her own Path_Str = ' ....../ParforProgMonv2/java' and pass it at this step: pctRunOnAll javaaddpath (Path_Str) – Garima Singh May 15 '15 at 10:25
  • Well that's not what you asked ;) I've updated my answer with a sample for Windows but I'm not able to test it to ensure it functions properly – sco1 May 15 '15 at 12:33
  • Thanks for providing elegant solution. I modified my question as well. – Garima Singh May 15 '15 at 12:50