How do I launch an application from a .sh script? - linux

Help me please with a bash script of a few lines.
I have a MyApplication executable in some folder, and I need to make a launcher script to call that application from it's folder when I click it from a grafical interface.
(I need this because I need my application to be launched from it's folder, so that Qt::currentPath() will return the current folder the executable is in)
Please help me, I just had to power off my linux machine two times in a row, I made fork bombs instead of launchers :(.
P.S. I'm a linux newbie, trying to figure out scripting.
EDIT
More about my current problem: Qt how to open a file in current dir ? or what's wrong with this?
Details: MyApplication is a GUI project compiled in Qt-Creator. It uses .xml files for storage. If I cd manually to the folder the executable is in, and run it, everything works fine, the application knows the path to the .xml files (current directory). But, if I just click the icon of the application it launches from $HOME, and my application is not able to find those .xml files.
That's why, I suppose, I need a .sh launcher, to call it from it's directory when I'll click it.

If its a graphical application, any sort of link will do. That works fine for me, unless you have something I'm not aware of, in which case please explain more.
Ps, fork bombs are limitable - http://forums.debian.net/viewtopic.php?f=10&t=44480&start=0

Related

How do I run code without the PyCharm IDE

Now that I am done with my project that was developed using PyCharm in a virtual environment, I need to distribute the code to my work machine; however, I am not certain on how to do this. Do I need to create a build of sorts so the code an run independently of the PyCharm IDE? Can someone please point me to the correct documentation on this crucial next step?
This really depends on what and how you're using the code for. If you just want to run it on your computer and it's a single file, you can open the command line/terminal and type python3 your_file_name and it will run the file (where your_file_name is the path to your .py file from whatever directory you're in). I assume you have python installed on your work machine, but if not, go here:
https://www.python.org/downloads/
If you have a more complex project or you want to deploy your code on a website or a server, these are probably good places to start.
https://www.jetbrains.com/help/pycharm/deploying-applications.html
https://docs.python.org/3.0/howto/webservers.html
EDIT: Added this as another useful link:
https://docs.python-guide.org/dev/virtualenvs/

Where to put Files for Mono Application in Unix

I am writing a C# application (in Visual Studio on Windows) that will be run as a mono application on Unix (Raspbian aka Debian). I am a Unix noob, and though I have read (well, skimmed) the Linux Foundation Filesystem Hierarchy Standard I am still not completely clear on where I should put the files my application will need. I have:
The compiled C# application (app.exe). I thought I would put this in /usr/bin, except that the application is not run directly (it is invoked by "mono app.exe"), so maybe /usr/libexec is a better location?
Configuration files (there may be more than one) (app.1.conf, app.2.conf, etc.). If they are not user specific, I would think /etc/app (a directory, not a file) would be a good place for these. How about if they are user specific? /home/?
Log file (app.log). Seems that /var/log is the right place for this.
Thanks in advance for your input.
You should look at an already established Mono app for reference. For example let's take MonoDevelop:
The exe file goes to /usr/lib/{appnameinlowercase}/bin/ , but they place a launcher script in /usr/bin, named {appnameinlowercase}, for easy launch from the command line (this script just calls exec mono YourAppName.exe).
In .NET the config files need to be in the same directory as the executable file, so you could place them in /usr/lib/{appnameinlowercase}/bin, then later for convenience, put symlinks to them from /etc/{appnameinlowercase}/.
Correct, /var/log/{appnameinlowercase}/ should be fine.

Issue with App.Config in the Startup Folder

I am writing a console app in c#.net. I have a batch file that currently copies the exe and exe.config to the startup folder on local machine from the network. It is set up that way so the user only has to run the batch file and then everytime the computer is started the exe will run.
Problem I am running into is that it also opens (or tries to open) the exe.config file as well. I am looking for the best workaround for this without it being overly complicated. Thought about putting the config file in a diferent location and then hardcoding the new location into the configuration manager but one of the concepts with the config file is to keep all hardcoded paths out of the code for easier updates if locations change. Also thought about putting a shortcut to the exe in the startup folder which would work but I want it to be transparant to the user. In other words all I want the user to do is run the .bat file once and forget about it.
Any help or ideas would be greatly appreciated as I am very new to .bat files
I like your idea of a shortcut, or for that matter a batch file pointing to the executable, with both the executable and config file located outside the startup folder.

Creating a menu item generically in Linux

For part of a large university project I have built a large java based application. To make "installation" cleaner I am aiming to write a script to copy the jar to a hidden file in the users home directory then add a menu &/Or desktop launcher.
Since I do not know what platform the markers shall be using it seems sensible to make this generic so I was going to build a shell script and a batch file.
The shell script starts off simple, check the directory doesnt already exist, make it and copy the file accross.
Then it comes to making a launcher of some kind. I presume each desktop environment shall do things differently.
After 10 minutes with google it seems everything suggested is autotools but since I have no knowledge of this it seems a bit overkill.
Is there an easy way to achieve what i need?
Thanks
These days, basically all of the desktop environments uses desktop files. For the specification for those files, see the Desktop Entry Specification.
Normally, they're put in /usr/share/applications on the system. Those files are then read and used to construct the menu.
If you have the ability to write to the system /usr/share/applications directory, that's obviously simplest, but if you had that, you would probably be putting the JAR file somewhere other than a hidden directory in the user's home directory.
If not, the path that's supposed to be honored is ~/.local/share/applications. If you drop a desktop file in there, it should show up for the user. (This is somewhat newer; I don't think GNOME 2 supports, it for example. Older desktop environments had various special places for these files.)
Then, the problem basically reduces to figuring out what to write for the Exec line in the desktop file. (See the desktop files on your system in /usr/share/applications for some examples.) If you're lucky, you can get away with just sticking a java command in there, but the details will depend on your application.

Running a Qt application at startup

I wrote a Qt application that is going to run on Linux. It supposed to run at startup.
It's supposed to run on every Linux- Suse, RedHat etc.
What script should I write and Where to put it?
I don't know how to write scripts at all, so I would appreciate it if you will attach an example.
You need to create a desktop entry file for your application (see here) and to put it in user's $HOME/.config/autostart directory.
Any desktop entry file in that dir will get executed when a Window Manager starts up (see here).
To do this, usually you'll need to create your desktop entry file by hand (that's it, not via C++ code/script) and to just install in that directory via C++ code.

Resources