添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello for some reason bat scripts work but ps1 scripts don't. Is there something special that needs to be done for powershell scripts?

I have the below script running as a gateway update event script and the ps1 and bat files are located in the same location. The delete tag increments for bat but not ps1

import time
	time.sleep(5)
#	gitEXE = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.bat"
	gitEXE = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.ps1"
	logger.warn(str(system.file.fileExists(gitEXE))) 
	system.util.execute([gitEXE])
	val = system.tag.readBlocking("[Ignition_Remote_IO_Gateway]aTestSharedFolder/delete")[0].value
	system.tag.writeBlocking("[Ignition_Remote_IO_Gateway]aTestSharedFolder/delete", val+1)
except Exception as e:
	logger.warn(str(e))```

@pascal.fragnoud , @kcollins1 I found an error. It was outside the logger I created.

Error executing project update script.

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "<[Data_Management] Update Script>", line 9, in File "<[Data_Management] Update Script>", line 9, in at java.base/java.lang.ProcessBuilder.start(Unknown Source) at java.base/java.lang.ProcessBuilder.start(Unknown Source) at java.base/java.lang.Runtime.exec(Unknown Source) at java.base/java.lang.Runtime.exec(Unknown Source) at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.io.IOException: java.io.IOException: Cannot run program "C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1": CreateProcess error=193, %1 is not a valid Win32 application

	system.util.execute([
		"powershell.exe",
		"-File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"

but it doesn't seem to be doing anything with no errors and I don't see the afile.txt in the data folder.

git-auto-commit.ps1 (simple create file)

New-Item afile.txt

I also tried

	import subprocess
	proc = subprocess.Popen(["powershell.exe -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	proc = subprocess.Popen(['powershell.exe', "-File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	output = proc.stdout.read()
	logger.warn(output)

but both those proc didn't work. First proc gave "[Errno 2] No such file or directory" and second proc gave "-File : The term '-File' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-c ... + ~~~~~ + CategoryInfo : ObjectNotFound: (-File:String) , CommandNotFou ndException + FullyQualifiedErrorId : CommandNotFoundException"

Thank you guys for the help so far

You're not structuring your commands correctly. Everywhere there's a space in a raw command line:
powershell.exe -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'
You need a new entry in the list you pass to system.util.execute or subprocess:

system.util.execute([
		"powershell.exe",
		"-File",
		"'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"
		"powershell.exe",
		"-File",
		"C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.ps1"

I didn't need the single quotes in the path