How to open xlsx file withough hanging a perl process - windows

I am trying to open a xlsx file in a Perl script with the command :
system("path_to_file\\file.xlsx");
The file is opened but it keeps the perl process hanged until I close the .xlsx file. How can I avoid that?
The file file.xlsx is created in the perl script. At the end of the execution I want it to be displayed to the user (like you would manually open it) and it works but it keeps the perl process hanging until i close it.

On Windows, system(1, $cmd) will run the command and immediately return without waiting for the child to finish. See perlport.
On Unix, fork and exec will work to this end.

Related

How to close a file using Shell?

I have a file opened named "C/Users/Desktop/textfile.txt". How do I close this using a shell script? I have tried taskkill, shutdown, "exec 1>&-" and others. Since I am new to shell, I am unable to figure out how to make it work.
textfile.txt is a non-executable file. That means you can't 'run' it, or 'kill' it. However, you can delete it - that is if some other process is not holding a lock on it.
If you want to release the lock, you have to first find the process that is holding a handle to this file, kill that process, and then the OS will let you delete the file.
From shell (command line), you can use this tool handle (https://learn.microsoft.com/en-us/sysinternals/downloads/handle) to identify which process is holding your handle. Once you get the pid (process id) from that tool, you can use taskkill to terminate that process and release the lock on that file.
c:\Program Files\SysinternalsSuite>handle.exe | findstr /i "c:/users/desktop/textfile.txt"
All said, you want to be careful when you terminate processes abruptly like this. The process won't get a chance to clean up behind itself.

Mac OSX Bash Script stop processing while specific window is open

I actually wrote a script that is compiling my LaTeX files and open the generated PDF in a viewer. That works fine.
cd Documents/my-bachelor-thesis/
latexmk 000_Root_Bachelor_Thesis.tex -pdf
open 000_Root_Bachelor_Thesis.pdf
ps -A | grep -m1 vorschau | awk '{print $1}'
So with the last line I get the PID of the process my PDF is opened.
There is the problem: I want stop my script process at the point the PDF is open. After I click on the close sign of the viewer, the process should continuo automatically. Is that somehow possible.
Current solution: I interrupt the process while waiting for some user input. After i type in something the process goes on.
echo "Can I proceed?"
read input
... more script
Thanks for helping me out.
Not familar with open in OSX. Quick search on man page suggests that you can force open to start new application, and wait until it finish by
open -Wn 000_Root_Bachelor_Thesis.pdf
Options:
-W Wait until the applications exit (even if they were already open). Use with the -n flag to allow open to function as an appropriate app for the $EDITOR environment variable.
-n Open a new instance of the application(s) even if one is already running.

CMD doesn't wait to finish process

When i use command
<path exc.xlsx>
it starts excel file working and wait until i close the file than i can type next command. My issue is that when other excel file is running cmd doesn't wait to close the file and goes to next line. It is necessary to type the command that will force cmd to wait until i close excel file even when onother excel file is running. I tried a lot of commands from the internet but no one seems to work properly. These were for instance:
start /wait exc.xlsx && exit
exc.xlsx cmd /k
exc.xlsx|rem
I'm using Windows7.
I try this method but it sometimes doesn't work properly. The line <os.rename> try to change name of the file. If it can it means that the file is closed and break the loop but using that the script sometimes can't open the excel file. I'm not as advanced as i would be and cant find another way to check if the file is closed.
import os
def is_open(file_name):
if os.path.exists(file_name):
while True:
try:
os.rename(file_name, file_name)
break
except:
continue
time.sleep(0.001)
is_open('exc.xlsx')
That's not very dignified and uses a lot of processor. If there is a way using programing language (preferably python) I can implement that in my script.

closing cmd after script is finished

I'm using python to run a script from a .bat file that opens a piece of software for data analysis. After the script is finished, the cmd is still open. How do I close it after the script terminates? Currently using:
subprocess.Popen('name.bat')

how to make my console in python not to close?

I'm making a application in python from Windows. When I run it in the console, it stops, shows an error, and closes. I can't see the error becase its too fast, and I can't read it. I'm editing the code with IDLE (the program that came with python when I instaled it), and when I run it with the python shell, there are no errors. I would run it from IDLE, but when I use the console, it has more features.
I don't know why this is happening. I need your help.
Run the program from an already-open terminal. Open a command prompt and type:
python myscript.py
For that to work you need the python executable in your path. Just check on how to edit environment variables on windows, and add C:\PYTHON26 (or whatever directory you installed python to).When the program ends, it'll drop you back to the CMD windows prompt instead of closing the window.Add code to wait at the end of your script. Adding ...
raw_input()
... at the end of the script makes it wait for the ENTER key. That method is annoying because you have to modify the script, and have to remember removing it when you're done.
Run your program from a Windows command prompt. That will not automatically close when the program finishes.
If you run your program by double-clicking on the .py file icon, then Windows will close the window when your program finishes (whether it was successful or not).
Create a text file in the program directory i.e. wherever your script is located. Change the extension to .bat for example text.bat. Then edit the text file and write:
python main.exe
pause
Now you can run the program without typing into the command console by double clicking the bat file, and the console window will not close.

Resources