Question

I have written a code in python with two functionality (say A and B). When I run these program through terminal, it works perfectly fine. Python codes include scapy module and PySide GUI. Now, I wanted an icon which will run the same program automatically, so I wrote a .desktop file. .desktop file is shown below.

[Desktop Entry]
Type=Application
Name=Covert Channel - Detection
Exec=python /root/Documents/path-to-code/detection.py
Icon=/root/Downloads/index.jpg
Terminal=false

Now, the problem is, out of two functionality A and B, only A is working. My friend has to same problem with some different code (in different language)

Note: Working OS is Fedora 20 32-bits in VMWare and I am logged in as root.

Was it helpful?

Solution

(using answer instead of comment to use nicer formatting)

This can be due to wrong working directories. Consider the following example:

testfile = open("testfile.txt", 'w')
testfile.write("TEST")
testfile.close()

stored in the file /tmp/subdir/test.py. If I now open a terminal and do the following:

cd /tmp/subdir
python /tmp/subdir/test.py

the testfile.txt is created in /tmp/subdir. But I can also do

cd /tmp
python /tmp/subdir/test.py

and testfile.txt will be created in /tmp, because it is the current working directory. You can even call python /tmp/subdir/test.py from your home directory, and the testfile.txt will be created there. It is now possible that "functionality A" works with any current working directory (cwd) and "functionality B" requires the cwd to be for example /root/Documents/path-to-code/.

Perhaps https://askubuntu.com/questions/50085/setting-the-working-directory might help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top