Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mkdir() and writing to it using popen()

Posted on 2006-11-29
3
Medium Priority
?
709 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 1400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…
Suggested Courses

783 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