Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

mkdir() and writing to it using popen()

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

790 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