Shell commands that depend on directories not working with .! (cd/cp)

Hello there.

I’ve been using Root for quite some time, and I’ve been using most shell (bash) commands with the .! to avoid switching back to bash just to run one command.

However, I have some issues with “cd” and “cp”.
Both of them seem to not detect the directories of the PC.

When I use .!cdthe directory I specify after it is not accessed.
The same goes to .!cpwhen trying to copy any file into another directory.
Although, when I copy files within the same directory I open Root in, the file is copied without issues. The problem seems to be basically switching between directories/paths. The same goes for all other shell commands that depend on specifying any path, like “mv” for example.

I know I can use gSystem -> ChangeDirectory("Dir")to change to whatever directory I want, but that still doesn’t help when trying to copy a file from the currect directory Root is opened in to another one.

Is there any way to be able to use cd and cp properly inside Root?

Hi,

The ‘.!’ (has to) create a new sub-shell at each invocation. Any change made to the shell environment (like ‘cd’ or ‘set’ of a variable) is lost once it returns (i.e. it is not seen in subsequent calls).

To make change to the shell environment for longer than one .! invocation, you need to use the gSystem interfaces (ChangeDirectory, Setenv, etc.).

I am not quite understanding under which circumstances cp fails for you, can you give a full session example?

Thanks,
Philippe.

Sorry for the trouble.
cp is indeed working, I don’t know why it wasn’t before, so it seems to be quite fine now:

root [0] .!ls testfile.cfg root [1] .!cp testfile.cfg testdir/ root [2] .!ls testdir/ tesfile.cfg

As for cd, here’s an example:

root [0] .!ls Makefile root [1] .!cd .. root [2] .!ls Makefile

So basically I’d have to use ChangeDirectory instead of cd from now on?

[quote]So basically I’d have to use ChangeDirectory instead of cd from now on?[/quote]Yes (or gSystem->cd(…); :slight_smile: :slight_smile: ).

Cheers,
Philippe.

[quote=“pcanal”][quote]So basically I’d have to use ChangeDirectory instead of cd from now on?[/quote]Yes (or gSystem->cd(…); :slight_smile: :slight_smile: ).

Cheers,
Philippe.[/quote]
Thanks for the tip! :slight_smile: