473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

os.system always opens new window on Windows XP/2000

Can anyone tell me how to run a bunch of commands in the same command
line window? When I do this:

system("command 1")
system("command 2")
....

it opens a new window for every system call. The alternative I can
think of is to write out the command to a batch file and run that, but
I'm wondering if there is a better way to do it.

Partly it is annoying to have 20 cmd windows flash on the screen, but
also I don't think it works if I do something like this:

system("set envvar=hi")

since I think the envvar does not persist once the command window is
closed.

thanks!
Jul 18 '05 #1
5 3063

John <oh***********@ yahoo.com> wrote in message
news:d0******** *************** ***@posting.goo gle.com...
Can anyone tell me how to run a bunch of commands in the same command
line window? When I do this:

system("command 1")
system("command 2")
...
If you just want to hide the console window, try
"win32process.C reateProcess"
If you want to set environment variables, I think batch file is OK.

Best Regards,
Kent Hsu

it opens a new window for every system call. The alternative I can
think of is to write out the command to a batch file and run that, but
I'm wondering if there is a better way to do it.

Partly it is annoying to have 20 cmd windows flash on the screen, but
also I don't think it works if I do something like this:

system("set envvar=hi")

since I think the envvar does not persist once the command window is
closed.

thanks!

Jul 18 '05 #2
Is there a reason why there is no way to run all the commands in the same
session? This is how the perl system function or `` works.

MB
If you just want to hide the console window, try
"win32process.C reateProcess"
If you want to set environment variables, I think batch file is OK.

Best Regards,
Kent Hsu

it opens a new window for every system call. The alternative I can
think of is to write out the command to a batch file and run that, but
I'm wondering if there is a better way to do it.

Partly it is annoying to have 20 cmd windows flash on the screen, but
also I don't think it works if I do something like this:

system("set envvar=hi")

since I think the envvar does not persist once the command window is
closed.

thanks!


Jul 18 '05 #3

"Moosebumps " <cr**@crud.co m> wrote in message
news:BV******** ********@newssv r27.news.prodig y.com...
Is there a reason why there is no way to run all the commands in the same
session? This is how the perl system function or `` works.
The system() function is, as the doc says, simply an interface
to the C library's system() function, with all the limitations that
implies.

You could certainly do it if you wanted to, but it's not the
default. You'd have to use one of the popen# functions
in the os module to start a shell and then feed it commands.

As to why it's not there, I suppose nobody has gotten around
to writing it and submitting it for evaluation for inclusion in the
core. That may say something about its perceived utility. Then
again, it may not.

You might want to join the discussion on PEP 324.

John Roth
MB

Jul 18 '05 #4
oh***********@y ahoo.com (John) wrote in message news:<d0******* *************** ****@posting.go ogle.com>...
Can anyone tell me how to run a bunch of commands in the same command
line window? When I do this:

system("command 1")
system("command 2")
...

Use os.popen("comma ndx")
This will return a file-like object from which you can read.
e.g. print os.popen("comma ndx").read()
will give you the console-output of "commandx".
But you must know what you're doing!
e.g. os.popen("comma nd") will start a console-window which
you won't see -- because you used this to avoid a console-window --
and after all I know, there's no chance to come back from this command.
it opens a new window for every system call. The alternative I can
think of is to write out the command to a batch file and run that, but
I'm wondering if there is a better way to do it.

Partly it is annoying to have 20 cmd windows flash on the screen, but
also I don't think it works if I do something like this:

system("set envvar=hi")
This command has no effect. You start a process in whose enviroment
%envvar% exists, but if you don't do anything in the context of this
process after the statement os.system("set envvar=hi") %envvar% will
be forgotten.
Better do: os.environ('env var']= 'hi'
Now the context is your python-script and all you do after this
statement will know %envvar% until your script will exit.

since I think the envvar does not persist once the command window is
closed.
True

thanks!


Regards
Peter
Jul 18 '05 #5
On 6 Jan 2004 10:45:59 -0800, oh***********@y ahoo.com (John) wrote:
Can anyone tell me how to run a bunch of commands in the same command
line window? When I do this:

system("comman d1")
system("comman d2")
...

it opens a new window for every system call. The alternative I can
think of is to write out the command to a batch file and run that, but
I'm wondering if there is a better way to do it.


I would recommend reading a little more about the os, shutil, and
system modules and doing it all in Python. I would especially advise
you to do that if you're seriously considering a batch file instead.
Unless you're going to have people without Python run the same batch
file, you may as well build your script in Python, which is something
it is touted for being good at.
--dang
Jul 18 '05 #6

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

Similar topics

9
4963
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
9
6958
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When his users run PC Anywhere from the shell, and minimize it, it minimizes to the system tray. With no task bar, there is no system tray, so there is no way to restore the PC Anywhere window. The shell starts PC Anywhere using ShellExecute. I...
3
1707
by: Austin | last post by:
My code is " os.system("NET SEND computer hihi") " i use this funtion on Windows server 2003. it's ok. But the same code running on Windows XP SP2, it shows the command window twice. How do i remove the command window?
3
9135
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
10
4304
by: CyberBless | last post by:
I have a page that opens a child window using window.open(...). How do I make so that when that child window opens you cannot get the focus back on the parent window unless you close the child window? Is it even possible?
4
3765
by: MrMike | last post by:
Hi. I have a hyperlink control (lnkViewLogData) which is assigned the following attribute when the page loads... Me.lnkViewLogData.Attributes.Add("onClick", _ "javascript:window.open('Input_New_Record_CustomerInformation.aspx?CustomerID=" & Me.lblCustomerID.Text & "','myWin','');") As you can see, when this attribute is assigned the hyperlink is formatted to pop open another window. The problem is that when the window opens, it...
0
1173
by: Jeanine | last post by:
Hi, I'm using the webbrowser control in a windows application in vb.net. When you navigate to a site, a new window is always opened. I have read various articles explaining how to use in MDI applications etc, and have tried these things, but still a new window opens when I use the navigate method. I need the browser to stay in the its parent control (ie form or panel control). Is this possible, any suggestions would be most...
4
4481
by: Roger Aikin | last post by:
I've converted a VB6 project to VB.Net 2005. (Actually using vstudio pro 2005). I'm on a machine that also has VB6 and Vstudio.net 2003 on it. The project uses Word, Excel, MapPoint and SqlClient (database is SqlServer 2000). OS is WinXP SP2. When I run the project, it opens the MDI form (MdiMain.vb) fine, but when I open one of the child forms and try to select something in a combo box (cboFilter2) it stops on a line of the...
7
3023
by: Andrew Poulos | last post by:
Is there a way for javascript to know if a browser has been set to open new windows in tabs? I'm trying to fix some code that allows a user to close a window that javascript opened and it seems to get confused what window to close when a new tab is opened. (The user clicks a link in the opened window which which opens a new window and close the current one.) Andrew Poulos
0
8603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.