Write command to gnome terminal with QProcess - qt

I am trying to write an application with Qt in Netbeans. I am able to open the gnome terminal (in Ubuntu), however I can't seem to get a command to be executed in the terminal once it is open, e.g. to execute the 'ls' command.
Can anyone perhaps help me with some code to execute the ls command in the gnome terminal once it is opened? I am opening the terminal with the following code:
QProcess *proc = new QProcess(this);
proc->start("gnome-terminal");
if (!proc->waitForStarted()) {
}

Use -e argument:
proc->start("gnome-terminal -e 'ls'");
To keep the window open, go to Edit > Profile Preferences > Command > When command exits and change to Hold the terminal open.

Related

how to open a true terminal window using paramiko?

Is it possible to open a terminal using paramiko like if we were executing gnome-terminal or xterm ? By terminal, I mean an actual terminal window and not a pseudo-terminal as it is done using invoke_shell method. I tried the recipe given here but it does not work.

When running script: "julia -i run/run_nf.jl", the error following error is displayed "Could not determine command"

When I input the command
"julia -i run/run_nf.jl" the error "could not determine command" is shown.
before the error is shown this is how my cd looks like:
After activating the project with the command "activate." The following text is displayed in purple color ""
Finally with the command "julia -i run/run_nf.jl" I run the script "run_nf.jl" that is located on the folder "run". However, instead of running the script the following error is displayed.
The instruction for running and installing the necessary pachages are described in detail here:
Instruction, which I am based to run my script
As #fredrikekre mentioned in the comments, you are trying to run a terminal command from the Julia REPL's PKG mode, which will not work. You have two options:
Run the command from inside the REPL's shell mode by first using the "delete" or "backspace" key to exit out of the Pkg mode (you will see the prompt change) and then typing in ; which switched the REPL to shell mode and then you can run that command.
Same as above in that you need to exit the Pkg mode by clicking the "delete" or "backspace" key on you computer, and then you can run (from the REPL) include("run/run_nf.jl") which will run the file (assuming that is the correct file path).
I will also make a PR to that package you linked above to update the docs to be more clear. Edit, link to PR: https://github.com/dynamicslab/NormalFormAE/pull/7

Command run in terminal but not in QProcess while PATHs are inserted

I want to run a command in Ubuntu via Qt using QProcess.
My command is fluent3DMeshToFoam <mesh address>
and when I run it into terminal its OK and produces sum output and files in a specific location. But I have problem with running it using QProcess.
I have noticed that I should add the path of fluent3DMeshToFoam to ProcessEnvironment of my QProcess object. So I did:
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("PATH" , "<path of fluent3DMeshToFoam>");
myProcess.setProcessEnvironment(env);
myProcess.start("fluent3DMeshToFoam" , QStringList() << "<mesh address>");
myProcess.waitForFinished(-1);
I connected readyRead() and errorOccurred() signals and after I run, the errorOccurred signal emits and the following error shows:
execve: No such file or directory
I searched alot and could not find out where the problem is.
thanks.
After a-lot of searches, finally I found-out that there was a problem with LD_LIBRARY_PATH which does not considered by Qt.
Without any using of setProcessEnvironment(...), I open terminal and export the LD_LIBRARY_PATH just before running it as follows:
export LD_LIBRARY_PATH
exec "./my_app"
Then my_app is aware of all libraries stored LD_LIBRARY_PATH

In order : launch new terminal, launch R environment in the new terminal, execute commands in R environment

I would like a shell script that launches a new terminal, opens the R environment in the terminal and executes commands in the R environment of the new terminal.
Here's what I did which is not working :
#!/bin/sh
for i in $(seq 25)
do
gnome-terminal -x sh "R; source('source.r'); function($i)"
done
Where, function() is an r function in the file "source.r"
Please help.
N.B. I don't want to launch the program using the command "Rscript"
EDIT 1 : I don't want to use the command Rscript because the execution halts after sometime (don't know why). In an R environment the script works fine though. Here's what I tried with the command Rscript :
#!/bin/sh
for i in $(seq 25)
do
gnome-terminal -e "Rscript script.r $i"
done
EDIT 2 : I found the reason why the script execution halted with the command Rscript. It was a bug in the code. Now I can make things work with what I did in EDIT 1. Would be nice to know if things can be made to work by not using Rscript i.e. launching R in different terminals and executing commands in each terminal from the shell script.

Running a command for every new window in tmux

I wrote this thing and I'd like to source a Python virtualenv activate script whenever a new window is created in a running session.
Is it possible? The default-command option is related to the shell, not an additional command.
I am making the following assumptions:
You are using bash
Your .bashrc file is source for each new window that starts a shell
You only want to start your virtualenv in a window that runs a shell
Add the code you want to run to your .bashrc:
if [[ $TMUX ]]; then
# code here
fi
This code will only run for new shells which are in an existing tmux session.

Resources