开发者

configure linux launcher to passed variables

开发者 https://www.devze.com 2023-04-07 04:14 出处:网络
I have found that i can use something called a launcher in linux by right clicking the desktop. i have set this to run my program in the terminal which i am happy about but i want to give it some def

I have found that i can use something called a launcher in linux by right clicking the desktop.

i have set this to run my program in the terminal which i am happy about but i want to give it some default values when it runs.

Im guessing i should put the values after the program path with - befor them but im not sure about what im doing.

can some point me to a document or something that lists the ways to include values and what i can include in the path.

also if i do this how will my program read them ? will they be passed to main ?

Is it possible to set it up in a way that the program does not know how many variable开发者_运维知识库s are coming at start up but will read as many as it gets.

im using c++.


If I recall correctly running a terminal is something like

rxvt -backspacekey  -sl 2500 -tn msys -geometry 80x25 -e 'script.sh -param' --login -i

-e command arg ... command to execute

So create a file named myApp.sh (pretty much an equivalent of a .bat on windows)

enter the following:

!/bin/sh
rxvt -geometry 80x25 -e 'yourExecutableName yourCommandLine' --login -i

After saving, just chmod +x on the file (so Linux will consider it as an executable)

chmod +x myApp.sh

After this, you can run it from anywhere on your machine (if the dir is in the PATH enviroment variable) or via double click in Gnome File Manager.

If you need to pass args also to the shell, you can access every single param with $0, $1, $2 (equivalents to %1, %2 in MS batch).

For command lines, a C/C++ program starts usually with a function main

int main (int argc, char ** argv) {
  exit(0);
}

argc is the number of arguments received in input, while argv is a pointer to an array of char * (the actual commandline), you may parse 'em directly.

PS: note that I use rxvt, you probably want to change this to xterm o gterm or whatever terminal you prefer to use.


You don't need C++ for this. Basically, you do it pretty much as you would do it under Windows, but the exact details depend on the window manager you are using (Gnome, KDE, etc.). The program information is passed to main via argv (which is also the preferred way of getting it in Windows, I believe). You do not have access to the raw command line.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号