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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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)
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
Thanks for providing elegant solution. I modified my question as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.