Solved

mkdir() and writing to it using popen()

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…

696 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