9.12.2024

Python3的py script呼叫其它的py script並執行

Ref: https://stackoverflow.com/questions/1186789/how-to-call-a-script-from-another-script

File test1.py:

print "test1.py"

File service.py:

import subprocess

subprocess.call("test1.py", shell=True)

The advantage to this method is that you don't have to edit an existing Python script to put all its code into a subroutine.

Documentation: Python 2Python 3


(當呼叫的py script是跟使用者有輸入輸出的互動時,

subprocess.call可以使得跟直接執行另一個py一樣)


Ref: https://stackoverflow.com/questions/51928521/eoferror-when-starting-with-subproccess


EOFError when starting with subproccess


You are using subprocess.Popen which is a by default non blocking, piece of code, hence You program cursor moves rather than waiting for the input from the user. But what you need is a code which is blocking your program cursor. subprocess.call exactly does it. It would be waiting for the other command to execute completely.

You need to use subprocess.call to solve your problem. Just change your script2 file with this

import subprocess
p = subprocess.call(["python", "abca.py"])

You can read more about the difference between subprocess.Popen and subprocess.call in this answer. Which describes when to use which command and the difference between them



Important Note:
If your script (a.py) contains a continuous loop waiting for user input
(as shown in your code),
subprocess.run() will not be able to handle it properly
because it doesn't support interactive input.
If you need to execute a script that requires user input,
you might want to use subprocess.Popen() instead,
as it allows more control over the standard input/output.

# Run the Python script a.py
result = subprocess.run(['python3', 'a.py'], capture_output=True, text=True)

# Print the output from the script
print(result.stdout)
print(result.stderr)

# a.py:
while True: print("AAA") print("BBB") print("CCC") user_input = input("Enter something (or 'exit' to quit): ") if user_input.strip() == 'exit': break print(f"You entered: {user_input}")

8.15.2024

Lua超新手無窮迴圈的陷阱

 以下Lua Code:

math.log2 = function (x)
    return math.log(x) / math.log(2)
end
...
 for i = math.floor(math.log2(n)) - 1, math.floor(math.log2(n)) do
 ...

n是 >= 0的整數,要注意for有可能造成無窮迴圈,
因為math.log(0)是-inf,不會彈出錯誤,
所以造成for變成無窮迴圈,而不只是做兩次…
另外注意,-inf跟同樣是-inf比對是true, 例如:
ath.log(0) == -3/0
==> true
若是nan比對,一定是false, 例如:
math.log(-1) == math.log(-1)
==> false

5.01.2023

如何在Windows 11 or 10遊玩SafeDisc保護的遊戲(純轉載沒試過)

 Ref:Microsoft Safedisc - Microsoft Community

Microsoft didn't make SafeDisc, it was created by the Rovi Corporation. You can learn more at: How to Play Games with SafeDisc or SecureRom DRM on Windows 10

is to use the one stop option - Driver Signature Enforcement Overrider 1.3b

I've never used this, but it does apparently work. However, I've been using noCD fix\hacks since I started using PC for games in 2004.


The easiest way to do this is to employ the Driver Signature Enforcement Overrider tool, which, when run as administrator, enables you to sign a previously untrusted file.

muo-gaming-w10-retro-drm-admin

Once you've acquired a copy of the SECDRV.SYS file (either by downloading it or copying it from the c:\windows\system32\drivers directory on Windows Vista, 7 or 8, and saving it to the same location in Windows 10), run the DSEO tool by right-clicking dseo13b.exe and selecting Run as administrator.

muo-gaming-w10-retro-drm-sign

Work through the subsequent dialogue boxes until you see the main menu and select Enable Test Mode then click Next.

This time, select Sign a System File, and browse to the SECDRV.SYS file in c:\windows\system32\drivers. Click OK, and wait while the driver is signed. You'll see the following message:

muo-gaming-w10-retro-drm-complete

Once you have followed the instructions to restart and then run DSEO again with Test Mode enabled, the driver should now be loaded by the game you've had trouble with, restoring your ability to play it.

(Should you be using Windows 10 Technical Preview, enabling Test Mode will result in a watermark appearing on your display. This can be removed using the Remove Watermark option in DSEO.)

Ref:NGOHQ.com

How to Play Games with SafeDisc or SecureRom DRM on Windows 10 (makeuseof.com)