473,385 Members | 1,901 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,385 software developers and data experts.

Help with os.system

Hello, I'm a newbie with Python and there are some things I don't
understand of os.system.

I've managed to write a script that works in order to test some
things:

import os
os.system('C:\\texmf\\miktex\\bin\\latex.exe "C:\Documents and
Settings\User\Escritorio\sample2e.tex" -output-directory "C:\Documents
and Settings\User\Escritorio"')
os.startfile('C:\Documents and Settings\User\Escritorio\sample2e.dvi')

This script launches the program "latex" and passes the input and
output file names and directories. Afterwards it launches a dvi viewer
to view the output.

I have 2 questions:

Why do I have to use double \\ in C:\\texmf\\miktex\\bin\\latex.exe
(if not it does not work)? And why not in the other places?

If I have the string "C:\Documents and
Settings\User\Escritorio\sample2e.tex" stored in a variable, how could
I use it?

Thanks in advance, miz.
Jul 18 '05 #1
2 1265
Mizrandir wrote:
Hello, I'm a newbie with Python and there are some things I don't
understand of os.system.

I've managed to write a script that works in order to test some
things:

import os
os.system('C:\\texmf\\miktex\\bin\\latex.exe "C:\Documents and
Settings\User\Escritorio\sample2e.tex" -output-directory "C:\Documents
and Settings\User\Escritorio"')
os.startfile('C:\Documents and Settings\User\Escritorio\sample2e.dvi')

This script launches the program "latex" and passes the input and
output file names and directories. Afterwards it launches a dvi viewer
to view the output.

I have 2 questions:

Why do I have to use double \\ in C:\\texmf\\miktex\\bin\\latex.exe
(if not it does not work)? And why not in the other places?
'\0', '\a', '\b', '\t', '\n', '\v', '\f' and '\r' are special characters.
Generally '\*' where * is a character is called "escaped character *",
it's a way to write/print a non-printable character.
E.g. '\t' is the Tab character. '\\' means the backslash character.

If you dont want the \ to be interpreted, use raw strings by prepending
a r before your string literal: r'C:\texmf\miktex\bin\latex.exe' will work.

If I have the string "C:\Documents and
Settings\User\Escritorio\sample2e.tex" stored in a variable, how could
I use it?


# let it be s:
s = r"C:\Documents and Settings\User\Escritorio\sample2e.tex"
# you can make your dir pathname by removing the last 12 chars:
d = s[:-12]
# better do it with os.path :
import os.path
d = os.path.dirname(s)
# then the whole command with
c = r'C:\texmf\miktex\bin\latex.exe'
comm = '%s "%s" -output-dir "%s"' % (c,s,d)
os.system(comm)

Read the tutorial at http://www.python.org/doc/current/tut for more ideas.

Hope this helps
--
Grégoire Dooms
Jul 18 '05 #2
> Hope this helps

Yes, thanks.

The second part (storing things in vars) I had already figured out
myself (but after posting).

The first (about \\) I imagined it was something like that but I
didn't know why in some places yes and not in others. But it's clear
now.

miz.
Jul 18 '05 #3

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
0
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if...
5
by: Steve Teeples | last post by:
Can someone point me to a document that clearly identifies the steps of creating a good help system for an application? I have a test tool that I'd like to add help to so that others will know how...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
3
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
6
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.