How to close the cmd window after the batch file run - python-2.7

I want to close the command prompt after the bat file run. From the bat file it's calling two python scripts and I have tried basic exit and many solutions to close the cmd in the bat file but non of were not working.
c:\python27\python.exe C:\Python27\EconomyNext\DetailEconomyNews.py %*
c:\python27\python.exe C:\Python27\EconomyNext\DetailFinanceNews.py %*
exit

Did you check this post:
CMD Script: How to close the CMD
It has a few options depending on how you are calling the CMD like:
exit /b
or
start c:\python27\python.exe
C:\Python27\EconomyNext\DetailEconomyNews.py %* &&
c:\python27\python.exe C:\Python27\EconomyNext\DetailFinanceNews.py %*
&& exit

A little late, but another option which worked from https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/
Running .BAT or .CMD files in minimized mode
To run a batch file in a minimized window state, follow these steps:
Create a shortcut to the .BAT or .CMD file. To do so, right click on the file, click Send To, Desktop (create shortcut)
Right click on the shortcut and choose Properties
In the Run: drop down, choose Minimized
Click OK
Double-click the shortcut to run the batch file in a minimized window state.

Related

Command window closing very quickly when running batch script with system()

I have an application developed using Borland C++Builder (Embarcadero nowadays) on Windows 10.
I want to launch a script contained in a .bat file from my app, using
the following code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
system("myfile.bat");
}
However, the command window appears then exits very fast, and I have no time to see the result.
I have added a pause command in the .bat file, but without success.
Below is the code for my .bat file:
#echo off
"./ttpmacro.exe" /I "./binary.ttl"
pause
Is there any solution to this issue?
I have resolved my issue by changing the path of the working directory. I have modified the path directory of the file "mybat.file" and then all things got OK.

In pycharm .py file is run in python console mode

When I ran my program in pycharm that time my .py file output came in python console mode and also did not see the "Run" option in below(before debug).Please help me to set "Run" option.So I can execute my program using "Run" option.Attaching screen shot.
current is :
Expected:

Console prompt window appear on system("start dir") but not on system("start ipconfig")

I try to create a simple UI which runs a command prompt in the background (but the windows console must not disappear) while clicking on each button, resp.
But before, I try something like system("start dir"); to see if the button works.
Here is the problem: when I click on the left button the windows console appear and don't exit unit I close it. But this only work with system("start dir");. If I change dir to ipconfig (or another call-function) the windows console will appear for a second and the exit. I tried something like system("PAUSE"); or getch(); etc, but it doesn't work.
Why does this command work with dir but not with another command?
There is a fundamental difference between DIR and IPCONFIG, the DIR command is built into the command processor (aka shell), IPCONFIG is a separate program stored in c:\windows\system32.
When you type START /? at the command line then you can see why it treats them differently:
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.
If it is not an internal cmd command or batch file then
it is a program and will run as either a windowed application
or a console application.
The alternative is to ask the command processor to execute the command and exit afterwards. You do with the /c option:
system("cmd.exe /c dir");
Or simpler yet, since system() automatically passes off the job to the command processor:
system("dir");
Just stop using start :)

How to open text file in notepad with cmd window in background?

I want to open a text file without opening cmd window in the background. I have tried:
webbrowser.open('file.txt')
but it crashes ArcGIS so I tried following:
os.system('file.txt')
it opens text file without crashing ArcGIS but cmd window remains in the background and goes away when I close text file.
It is more of a display choice question and just checking if there is any suggestion to avoid cmd window in the background.
I don't know if this is what you want, but maybe you should create .bat file (something like here) and run this with Python subprocess.
Save your script with a .pyw extension and the console window won't appear.
From the Python documentation :
On Windows systems, there is no notion of an “executable mode”. The Python installer automatically associates .py files with python.exe so that a double-click on a Python file will run it as a script. The extension can also be .pyw, in that case, the console window that normally appears is suppressed.
You need to modify the program that calls the "add-in script" to run it with pythonw.exe (and not python.exe which is the default).

Open command prompt from final builder

Is it possible to open a command prompt from inside final builder 6.. with the env created from inside final builder?
Yes, just use the Execute Program Action, set the Program File to %DOSCMD% and turn off Wait for Completion and Hide Window. Any environment variables you set in FinalBuilder will be available in the command prompt window.