System command 'cd' not working
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Craig Anderson
am 9 Nov. 2011
Kommentiert: Marco A. Acevedo Z.
am 18 Okt. 2022
I am experiencing a problem when trying to use the Matlab system command 'cd' to change the current system directory. On my laptop, it works fine. However, on my university desktop machine (networked mac pro), it doesn't seem to want to work no matter what I do.
For example, say I start in the directory /test. I verify this by typing > !pwd , which tells the system to print the current directory.
If I then assign a matlab variable a path string e.g.
> datapath = '/anotherdirectory/test2'
and then try to change into it by typing
> cd(datapath)
When I do this on my laptop, !pwd returns /anotherdirectory/test2. However, on my desktop, !pwd returns /test. No matter what I do, cd will not change the system directory outside the Matlab environment on my work machine. I've tried all sorts of variants to get the cd command to work such as
> system(horzcat('cd ',datapath))
as well, but without success. This is becoming a major pain for me, because none of my data reduction scripts are going to function if I cannot get this functionality to work without MAJOR overhauls. Anyone got any ideas? Perhaps it is some sort of permissions issue with my work machine, where it won't allow another program to perform system commands or something?
0 Kommentare
Akzeptierte Antwort
Daniel Shub
am 9 Nov. 2011
From your comment to Walter, it seems you are trying to change the directory of the "shell" from within MATLAB. It is not really clear what this means. What do you get if you do something like:
[a,b] = system('pwd; cd .. ; pwd')
This will be different then
!pwd
!cd ..
!pwd
The second case starts a new shell before and exits the shell after every command. The first case only create a single shell. How are you making your system calls?
4 Kommentare
Walter Roberson
am 17 Okt. 2022
system('cd /D D:\New\Path\Goes\Here; appropriate command goes here')
Marco A. Acevedo Z.
am 18 Okt. 2022
Thanks for the tip. My previous comment is not longer valid. Note that the ' /D ' represents the word 'another drive', not the letter of a different disk that follows up. :)
Cheers,
Weitere Antworten (2)
Walter Roberson
am 9 Nov. 2011
The first thing I would suggest trying is
which -all cd
just in case you somehow have introduced your own cd.m file .
Also, what does pwd (without the '!') return in each case?
4 Kommentare
Kaustubha Govind
am 9 Nov. 2011
Does your shell startup script always force the shell to start in a certain directory? I've seen that this has been the most likely cause for these issues in the past. One good way of testing this is to start a new shell window from within MATLAB and check if it always opens in a certain directory. I'm not familiar with Mac, but on Windows, you would use something like "!start &" to start a new system command window.
Konrad Gromaszek
am 13 Sep. 2018
Hello,
On my Mac code I've used
path_str = './MLP';
cd(path_str);
instead of
cd('./MLP');
... and it works!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!