473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding startup files


I'm creating an app that relies on a configuration file at launch. The file
will always exist in the app's installation directory, but I have no control
over where that might be.

Is there an OS-independent way that I can instruct the app to look in it's
home directory for startup files? Right now, I'm hard coding the path, which
won't work.

Thanks,

Jeff
Jul 19 '05 #1
12 1373
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))

Jul 19 '05 #2
On 2005-05-11, jeff elkins <je********@ear thlink.net> wrote:
I'm creating an app that relies on a configuration file at
launch. The file will always exist in the app's installation
directory,
That's the first decision you need to examine. If you want
work on Unix platforms, that's not where configuration files go.
If you're talking about Windows, then all bets are off and you
can ignore the rest of this post.
but I have no control over where that might be.
Exactly.
Is there an OS-independent way that I can instruct the app to
look in it's home directory for startup files?
No. That's not even the right place to look under Unix. If
you want to do things the "right" way under Unix, you look in
places like

/etc/<appname>
/etc/<appname>/whatever
/usr/local/etc/<appname>
/usr/local/etc/<appname>/whatever

One of the above would be used for system-wide configuration
stuff.

$HOME/.<appname>rc
$HOME/.<appname>/whatever

One of the above would be used for user-specific configuration
Right now, I'm hard coding the path, which won't work.


--
Grant Edwards grante Yow! I am covered with
at pure vegetable oil and I am
visi.com writing a best seller!
Jul 19 '05 #3
On Wednesday 11 May 2005 04:32 pm, he********@gmai l.com wrote:
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))


Works perfectly, thanks much!

Jeff

Jul 19 '05 #4
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))


That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.

--
Grant Edwards grante Yow! hubub, hubub, HUBUB,
at hubub, hubub, hubub, HUBUB,
visi.com hubub, hubub, hubub.
Jul 19 '05 #5
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))


That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.


Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of this
particular application (analysis of medical laboratory data) will be working
with Windows.

I'm totally new to Python (obvious,yes?) so how might argv[0] fail?

Jeff


Jul 19 '05 #6
jeff elkins wrote:
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))


That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.


Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of this
particular application (analysis of medical laboratory data) will be working
with Windows.

I'm totally new to Python (obvious,yes?) so how might argv[0] fail?


If I make a symbolic link to the executable script and run it using that
link, sys.argv[0] will give the filename of that link, not the real file
it points to.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #7
On Wednesday 11 May 2005 10:18 pm, Robert Kern wrote:
jeff elkins wrote:
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
The following script demonstrates a method that should work for you. I
believe it is entirely cross-platform.

#! /usr/bin/python

import sys
import os

print os.path.abspath (os.path.dirnam e(sys.argv[0]))

That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.


Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of
this particular application (analysis of medical laboratory data) will be
working with Windows.

I'm totally new to Python (obvious,yes?) so how might argv[0] fail?


If I make a symbolic link to the executable script and run it using that
link, sys.argv[0] will give the filename of that link, not the real file
it points to.

Thanks. I just tested that and it does indeed fail.

Jeff
Jul 19 '05 #8
jeff elkins <je********@ear thlink.net> writes:
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
> The following script demonstrates a method that should work for you. I
> believe it is entirely cross-platform.
>
> #! /usr/bin/python
>
> import sys
> import os
>
> print os.path.abspath (os.path.dirnam e(sys.argv[0]))


That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.


Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of this
particular application (analysis of medical laboratory data) will be working
with Windows.


Yes, but Windows these days supports multiple users. Are you sure that
you want to restrict your users to one configuration file per
installed version of the program?

I'm not sure Windows has a good solution to this problem. My
experiences with trying to share applications between users on Windows
haven't been very pleasant.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #9
On Thursday 12 May 2005 05:24 am, Mike Meyer wrote:
jeff elkins <je********@ear thlink.net> writes:
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
On 2005-05-11, he********@gmai l.com <he********@gma il.com> wrote:
> The following script demonstrates a method that should work for you. I
> believe it is entirely cross-platform.
>
> #! /usr/bin/python
>
> import sys
> import os
>
> print os.path.abspath (os.path.dirnam e(sys.argv[0]))

That will probably work most of the time, but...

1) you're not gauranteed that argv[0] contains the application
path/filename.

2) the directory containing the executable is not where
configuration files are supposed to be stored under
Unix/Linux.


Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of
this particular application (analysis of medical laboratory data) will be
working with Windows.


Yes, but Windows these days supports multiple users. Are you sure that
you want to restrict your users to one configuration file per
installed version of the program?

I'm not sure Windows has a good solution to this problem. My
experiences with trying to share applications between users on Windows
haven't been very pleasant.

<mike


With this particular app, a single config file per install is required. It
sets up parameters that may vary from laboratory to laboratory but never do
within a single lab.

However, it might be a good idea to check the environment and if running under
*nix store configuration (and data files, which I didn't mention) in a sane
manner. That would solve the symlink issue anyway...

Thanks for the feedback folks,

Jeff
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
5781
by: Neil Benn | last post by:
Hello, I'm looking at a small app which would need a very quick startup time for the Python interpreter. It doesn't do much (copying and caching of files, no GUI) but I need the Python interpreter to start up very quickly (<1 second on a Windows box). Is there a way to have a 'stripped' down Python interpreter which can start up very quickly on a windows box. Once thing I was thinking of was to use PyExe to make a quick startup (does...
2
1641
by: Andrew Wrigley | last post by:
Hi Is there any way to walk thru memory to find a variable that holds a reference to a recordset that has been left open? (I use ADO for my recordsets.) The reason I want this info: I am writing code to compact back end files.
3
3050
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the buttons work. The form's name ('frmMain') is selected from in the Startup dialog box.
2
1206
by: David | last post by:
Hi, Would someone please mind showing me how to obtain the absolute path to a folder that is created under the application folder at install time. ie. On my development machine the path is C:\engineering\development\software\BMSLITE\bin\Database On the target machine it may be c:\program files\orbit\bmslite\database
4
2431
by: Larry | last post by:
I have a Perl script using DBD::DB2, that runs during system startup on a Solaris system. The script is working fine during startup on many machines, except on one machine it fails complaining about a missing ".so" file, with Perl flagging the "use DBD::DB2" line. (I don't have the exact message since I'm heard about it from a remote sysadmin who only saw it scroll by on the console). However, if I login as root on that machine and run...
12
2026
by: chinkuang | last post by:
Hi Everyone: I have a question here: I used a startup object to protect my application - whenever PC starts up, I will check the setting of my application like registry, program files and so on, if they have been tampered then I will restore the original settings from the backup files I store in some hidden place. However now a guy said he has a tool that able to modify the Windows XP registry without even login to window - that means...
0
991
by: e'kong.tse | last post by:
Hi All, I'm trying to use C# to open up an Excel file that has a bunch of dependent files. Inside Excel, you can specify the startup files in Tools->Options->General Tab. My excel file has a reference to an .XLA file and links to 2 .XLS files. However, when I use C# to open up my excel file, only the .XLA file got open up but the 2 .XLS files didn't. So now I've a lot of #VALUE and #NAME errors in my excel file. Can anyone help me...
12
5743
by: rdemyan via AccessMonster.com | last post by:
I'm having a complicated linking problem. Before I get into the particulars, I'd like to know how Access links to the back-end file at startup, AFTER I've distributed my application to the client. Here's the issue. While I'm working on my app, I'm linked to the backend on my computer. When I distribute the app, the backend file is obviously in a different location (on the client server). But the first time my app is started up at...
3
1794
by: =?Utf-8?B?RVF1QWw=?= | last post by:
Hi, We have an application developed in VC2005 with mixed code, primarily C++ but using a C# dll for database access (DBUploader), the dll exposes a C++ interface. We are experiencing intermittent failure on startup - no errors or warnings are generated (including in the EventVwr). Once running there are no issues. The process is started either manually or spawned via a Windows service. The dll is compiled with the following compiler...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.