Solved

mkdir() and writing to it using popen()

Posted on 2006-11-29
3
687 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

786 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