473,569 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

os.system('cd dir1 ... and executing next os.system command in that directory (dir1)

Hello,

I'm having problems with os.system.

If I execute some 'cd directory' command with it, after that the script is
on the
same directory level as it was before the command.

Any ideas ?

Thanks in advance.
Jul 18 '05 #1
2 2993
Sami Viitanen wrote:
I'm having problems with os.system.

If I execute some 'cd directory' command with it, after that the script is
on the
same directory level as it was before the command.

Any ideas ?


os.system creates a new process that executes your command.
Python's own process is not affected.

You'll want to use os.chdir instead :-)

--Irmen

Jul 18 '05 #2
Sami Viitanen wrote:
Hello,

I'm having problems with os.system.

If I execute some 'cd directory' command with it, after that the script is
on the
same directory level as it was before the command.

Any ideas ?


If you use os.system, any environment or current directry changes there
will only affect your shell and the child processes of it, but never the
parent process (Python). This is true for at least Windows and *nix.

By the way, why don't you just use os.chdir? :)

-- Gerhard

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2031
by: Nicolas Fleury | last post by:
Hi, How can I know if a system command doesn't exist? All the ways I have tried behave like if the system command was existing but returning one. I don't want to sound provocative, but open in Perl returns an error in a command doesn't exist, so I'm sure we could have an exception in the same case for popen in Python? Thx and Regards, ...
1
2936
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. I want to trap the key combo and exit (somewhat) gracefully if the user decides to abort the program. I am using os.system for the system call, ...
0
1592
by: shanmugam | last post by:
Hi All How can i hide the command prompt window when executing the system command in perl. Thanks in advance Shanmugam
1
1456
by: roocell | last post by:
I'm running a system command on my server system(copy file.txt lpt1); to print a file to lpt1. This works fine on an XP machine and also works fine on the vista machine if i do it manually from a DOS prompt. I'm guessing it has something to do with User Acess Control (UAC) and elevating the PHP script or something.
8
10345
by: jkeith07 | last post by:
Ok so ive reached the end of my knowledge and have tried to find out how to do it and just plain dont understand it. I have a system call: system("db2cmd.exe \"db2 connect to vop9 user joebloggs using joesPassword&&db2 LOAD FROM \"d:\\vop9\\records_test.csv\" OF DEL MODIFIED BY COLDEL; METHOD P (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,...
1
2305
by: irvg | last post by:
I have a "for" loop to do something over a number of files in a directory. In particular I need to send a command line job that uses each file in thar directory as an input to node in a linux cluster. Here is how the "for" loop looks like: path = '/mypath/' for file in os.listdir(path): node_name = 'name' + ('%02d' % node) comand = 'ssh ' +...
2
2523
by: Selva123 | last post by:
Hi All, Greetings. May be simple issue but your help sought. I am executing the system command like $res=system("notepad.exe"); thro a perl file named aa.pl. At command prompt - when I enter perl aa.pl , I could see that notepad was opened but the control - I say as prompt ( in windows) does not return back. It looks like perl response...
2
3727
by: Selva123 | last post by:
Hi All, Greetings. May be simple issue but your help sought. I am executing the system command like $res=system("notepad.exe"); thro a perl file named aa.pl. At command prompt - when I enter perl aa.pl , I could see that notepad was opened but the control - I say as prompt ( in windows) does not return back. It looks like perl response...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.