You are not logged in.

1

Wednesday, March 23rd 2005, 3:39am

about command run

QProcess don't run whole command.
example:

Source code

1
2
3
4
5
QProcess *process=new QProcess(this);
process->addArgument("cd");
process->addArgument("..");
"cd /root"  , "clear" .....
How do I?

Thank you!!!

tuxipuxi-

Beginner

  • "tuxipuxi-" is male

Posts: 18

Location: Germany

  • Send private message

2

Wednesday, March 23rd 2005, 7:45am

QProcess doesn't emulate a complete shell. For changing the working dir, use QProcess::setWorkingDirectory() and then call clear.
However, I don't see how this could make sense. clear clears the screen of the current terminal, since you don't have one, there's nothing to be cleared.

Michael.

3

Wednesday, March 23rd 2005, 8:26am

I don't understand.
Do you give some code?
Thank you!!!

tuxipuxi-

Beginner

  • "tuxipuxi-" is male

Posts: 18

Location: Germany

  • Send private message

4

Wednesday, March 23rd 2005, 8:44am

I would have to know what you want to achieve to be able to give you example code.

Michael.

5

Wednesday, March 23rd 2005, 1:59pm

I want use process run "cd"command
Thank you!!!

bisserke

Beginner

  • "bisserke" is male

Posts: 32

Location: Belgium

Occupation: Right now my job is eatin' these doughnuts, or maybe...

  • Send private message

6

Wednesday, March 23rd 2005, 2:06pm

if you are working in a microsoft environment you could use "cmd.exe -c cd path/to/your/files"
Documentation is like sex: when it is good, it is very, very good. And when it is bad, it is better than nothing. - Dick Brandon

7

Wednesday, March 23rd 2005, 2:47pm

I working linux (Fedora core)
Thank you!!!

Jesse

Intermediate

  • "Jesse" is male

Posts: 194

Occupation: Systems Engineer

  • Send private message

8

Wednesday, March 23rd 2005, 2:58pm

use QDir;

QDir dir;
const QString path = "Some Path";

dir.setCurrent(path);


Cross platform.

9

Wednesday, March 23rd 2005, 3:16pm

Source code

1
2
3
QDir dir;
const QString path = "/";
dir.setCurrent(path);

But is not use.
I think know cd directory.
thank you for me help.

This post has been edited 2 times, last edit by "Worm" (Mar 23rd 2005, 3:18pm)


kandalf

Intermediate

  • "kandalf" is male

Posts: 276

Location: Argentina

Occupation: Developer

  • Send private message

10

Wednesday, March 23rd 2005, 3:18pm

What do you need to change directory for?
Kandalf
There's no place like ~

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

11

Wednesday, March 23rd 2005, 3:40pm

AFAIK there is no such program as "cd" -- it is implemented by shells (try calling "which cd" and you'll see that you don't have such tool in your path) and thus you can't call it via QProcess (well... you can, but it wouldn't have any effect on anything as the shell would end immediately). To change directories use QDir or QApplication methods.

Jesse

Intermediate

  • "Jesse" is male

Posts: 194

Occupation: Systems Engineer

  • Send private message

12

Wednesday, March 23rd 2005, 4:06pm

I think you may be able to use system("cd /");

tuxipuxi-

Beginner

  • "tuxipuxi-" is male

Posts: 18

Location: Germany

  • Send private message

13

Wednesday, March 23rd 2005, 4:45pm

Having the ability to read and understand seems to be luxury.
In my first post I told you that you can use

void QProcess::setWorkingDirectory ( const QDir & dir ) [virtual]
Sets dir as the working directory for processes. This does not affect running processes; only processes that are started afterwards are affected.
Setting the working directory is especially useful for processes that try to access files with relative paths.
See also workingDirectory() and start().


if you want to execute your command in a certain directory. Running "cd <whatever>" in a QProcess is just useless as it *isn't* a complete shell.

Read what we say or fuck off.

Michael.

14

Thursday, March 24th 2005, 2:25am

I try isn't ok
do you give whole code?
thank you.

GuestInTrouble

Unregistered

15

Thursday, March 24th 2005, 5:27am

regarding Qprocess and working directory

Hi,
I am also facing the relative path problems with Qprocess.I tried setWorking Directory in the following way:

I have the following folder heirarchy:
/Version/Temp and its in this Temp directory that I want to run my process.
I use the code like this:

QDir spumDir;
spumDir.setPath("Version/Temp");
spumProc->setWorkingDirectory(spumDir)

I get a memory referencing error.
And regarding using the cd command. If I use this command and change the path to Version/Temp then does it mean that now all my processes will get input and generate output from the changed path?
Thank you and sorry for replying and not generating a new thread- just tht that this was a related issue ...

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

16

Thursday, March 24th 2005, 11:33am

RE: regarding Qprocess and working directory

Quoted

Originally posted by GuestInTrouble
And regarding using the cd command. If I use this command and change the path to Version/Temp then does it mean that now all my processes will get input and generate output from the changed path?


If the process run by QProcess changes its path, only this process has a different path, not the parent or any other of its child processes.

Cheers,
_
Qt/KDE Developer
Debian User