Zombie process using xlwings - xlwings

When I use xlwings to automate stuff in excel, I still have EXCEL zoombie process running even if I quit the application (with wb.Application(wb).quit()).
Thus, when I try to re open my excel file that bugs. I have to manually kill the excel application.
edit : I use the xlwings 0.7.0

The issue is that wb is a global reference to your workbook which still exists even after executing the quit command. Excel sees that it is being referenced (through COM) and thus refuses to shut down properly.
For now, you can manually clean up your workbook object after quitting: del wb. In the next major release of xlwings, we'll also provide a new Book.kill() command that will get around this issue.

Related

How to pass argument to Outlook.exe while running it without using power shell or other application using C++, MFC/MAPI?

I have my plugin written in MAPI C++ for outlook.
There is one requirement wherein if user does GAL delete, I want to clear the cache of outlook for which there is a switch /CleanAutoCompleteCache which will clear the whole AutoComplete list of outlook.
Now I know that I can do it by any power shell script or something but I want to do it from my code only. i.e the code from which outlook gets restarted automatically.
OR
Is there a way to pass this /CleanAutoCompleteCache switch while user opens outlook by double clicking the icon or Outlook.exe file?
You can specify command line arguments when your application starts a new process, for example, to start an external application you could use the following code:
#include <stdlib.h>
...
system("cmd.exe")
The second argument allows specifying parameters.
However, you need to close Outlook before launching a new instance and applying the command line argument for clearing the autocomplete list. For that reason, you can develop an external application which can launch Outlook with a specified command line, but that application should be scheduled from your add-in to run and when the outlook.exe process doesn't exist. So, in your VSTO add-in you schedule the external application (or just run it and wait until Outlook goes out from the list of running applications) and close Outlook (see the Quit method of the Application class).

Start .exe file and automatically "press enter for "Save"" in SAS

I have a SAS program I would like to schedule, so we don't have to run it manually.
In the program we call an excecutable (reg.exe), like this:
X CALL "K:\reg.exe";
The executable opens a standard windows save-dialog and all we need to do is press save, which will save an xml-file. The save-dialog already opens in the correct directory.
What I would like is to somehow pass the instruction on, using code, to "press save", so the program can move on and work with the saved xml-file.
Is this possible somehow?
Thanks for your help!
Thomas:
There are numerous Windows utilities for scripted control of an interactive program. For example: AutoIt (my favorite), MouseRobot and AutoHotKey to name a few.
The statement
options xmin noxwait noxsync;
will cause the external program to run, not wait for the command session to exit, and not wait for the command to complete.
If your SAS programs needs to wait for the side effects of the scripting use of reg.exe to occur before occurring, use:
options xmin noxwait xsync;
These settings affect other operating system interfacing features, such as:
X command
CALL SYSTEM routine
%SYSEXEC statement
The use of your reg.exe might require your login to have admin rights.
The SYSTASK statement can also run external commands.
If you find that you are unable to run external commands, it is probably because the system setting NOXCMD is active. This setting is on by default in SAS server environments.

Used System function to open an excel sheet

I'm using System function System(mypath/test.xls) to open and edit an excel sheet in C++ run time. It opens my excel sheet, allows me to edit ans close the same. After closing the excel sheet, the control goes to the code again. Everything works fine unless there is already some other excel sheet opened. If there is some other excel sheet already opened in the machine, I will not able to edit and close so that control goes to code. Can anyone suggest any solutions for this issue.
What is happening is your System(..) function call is asking the Windows shell to find the application associated with your file (test.xls) , which is Excel. Then if Excel is already running it is asked to open file. If the application is not running, then Windows starts the application for you.
So if the application is not already running and it is started for you it becomes associated with your program as a 'child' process. Therefore your System(..) call waits for it to end before continuing. If however Excel is already running then once Windows informs that instance of your desire to open the file test.xls, your call to System(..) returns immediately.
You can avoid this by explicitly running the Excel program by giving the full path to the Excel EXE file. And including the /x command line argument and full path to your file. The /x causes Excel to open a new process and then open your file. This new process is a child of your program's so the System(..) call will wait..
I'm not familiar with the System(..) call (is it like the system(..) one?) you may have to provide the switch /x, and path arguments as distinct arguments to this call rather than in one long string. Also there may be options on how your child process is launched, so waiting for it to return may be optional and so forth.

Shell script execution - Error handling

I am designing a gui application using qt creator. In there if i press a button, values from a .csv file gets imported to an sqlite3 database table.
For doing this I have used the QProcess to launch a shell script that contains the commands for importing data.
void MainWindow::on_pushButton_clicked()
{
QProcess process;
process.startDetached("/bin/sh", QStringList()<< "/home/aj/myscript.sh");
}
and myscript.sh for importing is--
echo -e '.separator ","\n.import import_table.csv test_table' | sqlite3 testdatabase.db
the reason behind this approach is that dot-commands can not be integrated directly to the c++ gui program without creating custom parsing solutions.
Now, this approach (QProcess and shell script) works perfectly well for me. But one bottle neck is it does not offer any error-handling/identification.
For example if the import command stops midway during data retrieval or all the values in .csv are not imported I would not know the problem. Is there any way to know if problem has occurred during importing ??? (redirecting the message via QDebug???)
QProcess has a member function called exitCode() which oddly enough returns the exit code of the process.
http://qt-project.org/doc/qt-5/qprocess.html
Finding that answer required a 10-second search in google for the documentation...

Open SAS program in new instance

I'm trying to figure out a way to open SAS programs in new instances of the Enhanced Editor by default on click.
The question has been asked before but no luck.
This paper describes the way a program is opened with the Enhanced Editor. The full command is :
"C:\PROGRA~1\SASHome\SASFOU~1\9.3\core\sasexe\SASOACT.EXE" action=Open
datatype=SASFile filename="%1" progid=SAS.Application.903
The author explains that:
The sasoact.exe program is used to launch an OLE automation session of SAS.
Automation
is a mechanism through
which one Windows application can control another application programmatically. When you double-click a SAS file
type, sasoact.exe checks to see if an existing OLE automation session of SAS is running. If not, it then invokes an
OLE automation session of SAS. Once there is an active
SAS automation server session, any further calls from
sasoact.exe are handled by the existing SAS session instead of in a new
SAS session.
I guess having only one OLE session is usefull in some way or another but it's really annoying when you have to manually open a new EE instance every time you want to run multiple jobs. Not to mention that sasoact targets the first session initiated and if a job is already running on that session well your program is not going to open.
Is there a way to directly request a new instance of the OLE session or perhaps "trick" sasoact.exe into not seeing the opened sessions ?
[EDIT] Well too bad it's been closed as duplicate because the answer is substantially different than the other question's. Also it might help others who do not want to run their programs from a batch file.
Here is the registry key that works:
"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -initstmt "dm 'whost;include ''%1'' ';"
I added it in HKEY_CLASSES_ROOT\SAS.Program.701\shell\Open New\command so now I have a neat little extra option in my drop-down menu that effectively opens programs in new sessions on click:
A similar thread showing the use of a batch file to open a SAS program in a new session is available here.
If you want to open a .sas program in a new session by simply clicking the program here is how to do it:
You have to add an entry to the registry. Be careful when messing around with registry files, always back up your entries.
Open the registry editor (WIN+R > regedit).
In the directory HKEY_CLASSES_ROOT\SAS.Program.701\shell\ create a sub-directory with a meaningful name(right-click on shell > New > Key). I named mine "Open New". In this new sub-directory create another sub named command. You should now have a path that looks like:
HKEY_CLASSES_ROOT\SAS.Program.701\shell\Open New\command
In here, right-click on the file on the registry file on the right > Modify and add the following in the Value data field (change the path of sas.exe if needed)
"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -NOTUTORIALDLG -initstmt "dm 'whost;include ''%1'' ';"
Close the editor. You should now have the new option specified in the drop-down menu of the right-click on a .sas program:
This option will open your program with the Enhanced Editor in a new SAS session.
Now if you want it to work for double-clicking I suppose you'd have to replace the value in the Open sub-directory with the one from above. I haven't done it and I don't recommend it, the extra option in the drop-down is enough for me.