Solved

mkdir() and writing to it using popen()

Posted on 2006-11-29
3
683 Views
Last Modified: 2011-10-03
I have a commandline process
and use that to write in a directory I just created using mkdir()
Nothing appears
If I copy the code of the command line call
and run it in a batch file
The file gets created

Two questions
- is there a lock on a freshly created directory that prevents the sub process to write to it
- is popen() the best way to launch a command line execution (I don't need to attach streams to it, simply execute)

Thanks

Geert
0
Comment
Question by:Geert Bormans
3 Comments
 
LVL 15

Accepted Solution

by:
efn earned 350 total points
ID: 18042527
There isn't any universal kind of lock on a newly created directory.  It is possible that default permissions could be set so as to block writing in the directory, but this would be unusual.

If you don't need to send the command input or read its output, os.system is simpler than popen.  You might give it a try.
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 18044426
You should post your code.  Both popen() and system() work fine for me on both Windows and Linux:

import os
os.mkdir("New")
os.chdir("New")
os.popen("echo One > One.txt")
os.system("echo Two > Two.txt")

Are you sure you're running the command line in the right working directory?  Do you need to call chdir()?
0
 
LVL 60

Author Comment

by:Geert Bormans
ID: 18045102
Thanks

using system revealed a new problem.
What happened is this
My script worked, the system call as well, I created the subdir, added the subdir to the path and the system call no longer gave results
Since I was not yet catching what popen has to tell me, I got some real errors thrown in my face that are a bit strange to me

I have posted a new question to follow this up
http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_22077684.html

thanks for your help sofar

Geert
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now