Frage

As per my question, I am unable to execute "export" command in linux via Qt.

I tried QProcess, but it didn't worked.

Actually I need to set Proxy Address in Linux OS. The command to set proxy address is:

$ export http_proxy=http://proxy-server.mycorp.com:3128/

I want to execute this command via Qt. I tried using QProcess, but it didn't worked.

I also tried QProcessEnvironment as mentioned here.

Can any one suggest me better way to executed this command ??

Also is there other way to set Proxy Server on Linux via Qt ??

Any idea/suggestion would be highly appreciated.

I am using Qt 4.7.4 (Cannot switch to higher version as per company policy)

War es hilfreich?

Lösung

export isn't eucutable file, Qt process uses exec C function , So you can't do it, you can run ls -l, but export , set ,you can't run bash built-in commands. you should direct uses C function for environ-variable. if you read man getenv you can solve your problem.

For your case, you can do via setenv C function.

Andere Tipps

As mentioned above; export is not an executable file, it is a built-in bash command. The exec variant functions by their nature, replace the current process image with a new process image. Therefore, you can only use exec variants on executable programs or processes. In Unix/Linux operating systems, every process has its own environment variables. You can get those key-value pairs by reading environ variable, which is declared in unistd.h header file as an extern char** pointer-to-pointer variable.

Environment variables are inherited by child process created by the parent process. If you use setenv/putenv functions to create a new environment variable in your program, this new variable will only be granted in your parent and nested child processes until they exit or terminate. If you would like to make these variables permanent, you will need to set them in a startup shell script.

In Linux systems, bash runs the following script files before it shows up:

  • /etc/profile
  • /etc/bashrc
  • ~/.bash_profile

If you embed your environment variables as export key=value commands in the shell script, which is going to be started up by bash that your main program will run on top, you might access them from your program or terminal itself.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top