473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Windows commands

13
Hey guys, i'm back.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import os
  3. os.system("mkdir c:\test")
  4.  
  5.  

Why doesn't this work? It should work. But it doesn't. How can I use commands in windows through the os.system module.

This is a module right? Or a library. I don't know.
Apr 3 '07 #1
4 1490
gloomer
13
Ok this is officially messed up.

My python .py script is in the My Documents folder.

I execute it, and oh no, it does not create the folder "test" in C:\

It creates the folder "est" in My Documents.

How does it make "est" out of test!!!!??

I did not miss spell it. Seriously. What i'm I doing wrong?
Apr 3 '07 #2
\ is escaping the next character t so \t is replaced with a tab character. The command you're really sending it is 'mkdir c: <tab> est'. The chacter for '\' is actually '\\' so try the following.

import os
os.system("mkdir c:\\test")
Apr 3 '07 #3
gloomer
13
Ahhhh. Now I get it. Thanks a ton.
Apr 3 '07 #4
ghostdog74
511 Expert 256MB
Hey guys, i'm back.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import os
  3. os.system("mkdir c:\test")
  4.  
  5.  

Why doesn't this work? It should work. But it doesn't. How can I use commands in windows through the os.system module.

This is a module right? Or a library. I don't know.
An advice, try not to use the system's mkdir to do this particular task of making a directory. The os module comes with the mkdir() method for this purpose
Expand|Select|Wrap|Line Numbers
  1. import os
  2. yourdir = os.path.join("c:\\","test")
  3. os.mkdir(yourdir)
  4.  
this will make your code more independent of the platform you run your script.
Apr 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Moosebumps | last post by:
So, after reading some messages about os.system, and looking at the popen stuff and trying it a bit, I still have not found a way to keep a command window open for several commands (on Windows...
4
by: Adam Clauss | last post by:
I am currently developing an application which will primarily run as a service that starts with Windows. However, I want to also have an 'administration' tool that can be run that controls various...
2
by: fperfect13 | last post by:
Hi, I have the folowing exception Exception : System.NullReferenceException: Object reference not set to an instance of an object. 00000019 3:30:48 PM at...
2
by: Harley | last post by:
Hey, I want to have a small command prompt type shell in one of my forms that will allow a user to issue dos(if i can still call it dos) commands from within my windows for and show the output...
5
by: Brian Patrick | last post by:
I have an application model which will consist of a front-end configuration application, which needs to control the state of a back-end vb.net windows service (which is the component that does all...
7
by: Rich | last post by:
I have the following script on all pop up windows, would like to have this work on all newer browsers if possible. Right now it only works on MSIE & Opera. Not sure why. Any suggestions are...
8
by: JimS | last post by:
In my environment we are using DB2 UDB for Windows for development and DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of columns that permit nulls may be enforced with a unique...
14
by: miago | last post by:
Searching this forum I found an example of running Unix commands from Python;I wonder if there is a way to get the output of windows commands on a string using Python.Thanks in advance; Miago.
2
by: SrivalliBapathi | last post by:
Hi, Please help me, if theres a way we can execute DB2 commands directly from the windows cmd prompt window instead of executing those from DB2 CLP window. I need to connect to a DB2 database...
4
by: fang | last post by:
Dear all: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work. But they do work in IDLE. please teach me about...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.