473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Getting real argv[0] in python

I need to be able to obtain the real argv[0] (not the script name).
The application is writing a CUPS backend in python. For some reason,
CUPS decided to pass the URI as argv[0] (perhaps to ensure that CUPS
will only ever run on Unix, since CUPS stands for Common *Unix*
Printing System). The only solution I can think of is to write a C
wrapper that inserts the original argv[0] before execing python with
the script.

Is there already a way to do this that I have missed?

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

Jul 18 '05 #1
1 4165
On Tue, 28 Oct 2003 13:52:26 -0500, Stuart D. Gathman wrote:
I need to be able to obtain the real argv[0] (not the script name).
The application is writing a CUPS backend in python. For some reason,
CUPS decided to pass the URI as argv[0] (perhaps to ensure that CUPS
will only ever run on Unix, since CUPS stands for Common *Unix*
Printing System). The only solution I can think of is to write a C
wrapper that inserts the original argv[0] before execing python with
the script.

Is there already a way to do this that I have missed?


Here is the simple C wrapper I am using:

#include <stdio.h>
#include <string.h>
#include <unistd.h>

static const char scriptdir[] = "/usr/lib/cups/python/";

int main(int argc,char **argv) {
char *nargv[10];
char script[256];
const char *p;
int i;
int slen,len;
if (argc > 7) {
fputs("Usage: pycups uri ...",stderr);
return 1;
}

p = strchr(argv[0],':');
if (p)
len = p - argv[0];
else
len = strlen(argv[0]);
slen = strlen(scriptdir);
strcpy(script,scriptdir);
if (len + slen + 4 > sizeof script)
len = sizeof script - slen - 4;
strncat(script,argv[0],len);
script[slen + len] = 0;
strcat(script,".py");

nargv[0] = "python2";
nargv[1] = script;
for (i = 0; i < argc; ++i)
nargv[i+2] = argv[i];
nargv[i+2] = 0;
execvp("python2",nargv);
perror("exec");
return 1;
}

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

Jul 18 '05 #2

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

Similar topics

3
by: Bolin | last post by:
I was wondering how to get some system info from a PC running Windows in python. I am especially interested in knowing how much RAM the computer has, how much diskspace is still left, and what jobs...
2
by: Alberto Santini | last post by:
I ported a Jos Stam's demo about Fluid mech to check the difference of speed between C implementation and Python. I think I achieved good results with Python and there is space to improve, without...
6
by: mg | last post by:
Hello, I am writting bindings for a FEM application. In one of my function 'initModulename', called when the module is imported, I would like to get the argc and argv arguments used in the main...
4
by: Allan Adler | last post by:
I'm trying to reinstall RedHat 7.1 Linux on a PC that was disabled when I tried to upgrade from RH7.1 to RH9. This is presenting lots of unexpected difficulties. Apart from wanting to keep the old...
5
by: David Rasmussen | last post by:
If I have a string that contains the name of a function, can I call it? As in: def someFunction(): print "Hello" s = "someFunction" s() # I know this is wrong, but you get the idea... ...
1
by: poggle.themammal | last post by:
The python tutorial says "When the script name is given as '-' (meaning standard input), sys.argv is set to '-'. When -c command is used, sys.argv is set to '-c'. " but when we use a command say...
2
by: iwl | last post by:
Hello, I'm just starting with Python - would like to embed it in my windows-programm as an script-processor. For tests I use easygui some easy-wrapper for the py-tck-stuff. ...
0
by: Gordon Fraser | last post by:
Hi, I'm trying to parse Python code to an AST, apply some changes to the AST and then compile and run the AST, but I'm running into problems when trying to evaluate/execute the resulting code...
0
by: Orestis Markou | last post by:
Have you tried passing in empty dicts for globals and locals? I think that the defaults will be the *current* globals and locals, and then of course your namespace is broken... On Tue, Oct 7,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.