WshShell.Run always returns exit code 0 - windows-server-2012

I've executed WScript on windows Server 2012 R2 and WSH version 5.8.
I've called WshShell.Run(command.bat, 1, true), but it always returns exit code 0.
The command.bat return exit code 1. But the WshShell.Run(command.bat, 1, true) return 0.
How can I return the correct exit code 1?

If your command.bat executes succesfully it will return 0 if it has an error it will return 1.
If I understand your question you want the WScript to return the return value of the command.bat to that end you can do this:
var WshShell = WScript.CreateObject("WScript.Shell")
var bat_return_value = WshShell.Run("command.bat", 1, true)
WScript.Quit(bat_return_value)

Related

Python pylibmc syntax / how can I use mc.set in a loop

I want to set keys in a for loop, and read them back in another script also using a loop.
To test memcache is working I made these simple scripts:
a.py
import pylibmc
mc = pylibmc.Client(["127.0.0.1"], binary=True,
behaviors={"tcp_nodelay": True,
"ketama": True})
mc["key_1"] = "Value 1"
mc["key_2"] = "Value 2"
mc["key_3"] = "Value 3"
mc["key_4"] = "Value 4"
b.py:
import pylibmc
mc = pylibmc.Client(["127.0.0.1"], binary=True,
behaviors={"tcp_nodelay": True,
"ketama": True})
print("%s" % (mc["key_1"]))
print("%s" % (mc["key_2"]))
print("%s" % (mc["key_3"]))
print("%s" % (mc["key_4"]))
This working fine. But I have no clue how to rewrite memcache line to be used in a for loop.
I tried several things, but nothing I tried did work.
What I want is something like this:
for index in range (0,4):
mc["key_(index)"] = "Value (index)"
you can use f-strings:
for index in range (0,4):
key = f"key_{index}"
mc[key] = f"{mc[key]} {index}" # or "Value {index}"

XGetWindowProperty and ctypes

Question
I'm trying to find NET_WM_NAME property for each of the window/client that X11 reports. Problem is that there's nothing returned - number of items is 0 and returned data results in empty string. I've looked at multiple code examples through out github and examples written in C and C++ , specifically Why is XGetWindowProperty returning null? as well as Xlib XGetWindowProperty Zero items returned , however I cannot find where is the problem with my code. Seemingly everything is fine, order of parameters passed to XGetWindowProperty function is in accordance with documentation, and the function returns success status, but results are empty. Where is the problem with my code ?
Code
Below is the code I am working with. The issue is xgetwindowproperty function. The other parts below it work fine, and are provided only for completeness.
#! /usr/bin/env python3
import sys
from ctypes import *
def xgetwindowproperty(display,w):
actual_type_return = c_ulong()
actual_format_return = c_int()
nitems_return = c_ulong()
bytes_after_return = c_ulong()
prop_return = POINTER(c_ubyte)()
wm_name = Xlib.XInternAtom(display,'_NET_WM_NAME',False)
utf8atom = Xlib.XInternAtom(display,'UTF8_STRING',False)
print('_NET_WM_NAME',wm_name, 'UTF8_STRING',utf8atom)
# AnyPropertyType = c_long(0)
status = Xlib.XGetWindowProperty(
display,
w,
wm_name,
0,
65536,
False,
utf8atom,
byref(actual_type_return),
byref(actual_format_return),
byref(nitems_return),
byref(bytes_after_return),
byref(prop_return)
)
print(nitems_return.value) # returns 0
# empty string as result
print( 'Prop', ''.join([ chr(c) for c in prop_return[:bytes_after_return.value] ]) )
Xlib.XFree(prop_return)
print('#'*10)
# -------
Xlib = CDLL("libX11.so.6")
display = Xlib.XOpenDisplay(None)
if display == 0:
sys.exit(2)
w = Xlib.XRootWindow(display, c_int(0))
root = c_ulong()
children = POINTER(c_ulong)()
parent = c_ulong()
nchildren = c_uint()
Xlib.XQueryTree(display, w, byref(root), byref(parent), byref(children), byref(nchildren))
for i in range(nchildren.value):
print("Child:",children[i])
xgetwindowproperty(display,children[i])

How to check if a method returns a non zero exit code in Groovy

I have a Jenkinsfile project that requires me to include an 'if statement to ascertain if shell commands within certain methods return an exit code outside of 0.
The first method method 1 works as expected. However i would like to include an if statement to skip the second stage since that shell command in method 2 doesn't exit with 0.
def method1(setup){
sh """
echo ${setup}
"""
}
def method2(setup){
sh """
ech ${setup}
"""
}
node {
stage('print method1'){
method1('paul')
}
// I need an if statement to skip this method since the if statement returns non=zero
stage('This method should be skipped'){
if(method2 returns != 0) //This if condition fails but need something similar to this
method1('paul')
}
}
Any help with this is much appreciated.
You use a default sh step execution in your example which means that exit code is not returned from the command. If exist status is something else than 0 in such case, pipeline fails with the exception. If you want to return exit status and allow the pipeline to continue you have to pass returnStatus: true option, for instance:
int status = sh(script: """
echo ${setup}
""", returnStatus: true)
if (status != 0) {
// do something
}
Source: sh step pipeline documentation

docker api ContainerExecInspect cannot get correct exit code

I am using docker engine-api(github.com/docker/engine-api) to execute some command
I use client.ContainerExecCreate and then client.ContainerExecInspect to run my command and then get the command exit code(I run multiple commands in the same container so the exit code get from ContainerInspect is useless for me.)
This is my function use to execute command in container
http://pastebin.com/rTNVuv9T
but ContainerExecInspect return wrong values sometime, because sometimes ContainerExecInspect is called before the command exit and it said exit code is zero, which is wrong
And I wrote a testcase to test it
http://pastebin.com/PED1Rf4k
And the result will not be 233, it will be 0
I have set ExecConfig.Detach = true and ExecStartCheck.Detach = true, but no helps
Is there any way to wait until the command exit then get the exit code?
Addition:
For some of my command running is shell script not a executable, so I think I need to prefix /bin/bash, and wait the container exit, is not what I want, I want to wait the command exit, and the container is still running
I think now I can solve my problem
The main point is when using containerExecAttach it will exposed the hijacked connection and, I can judge whether the command exit by read from the connection until EOF
There are a few point to set then
Should set ExecConfig AttachStdout to true
Then read from hijacked conn
Here is a sample code
atinfo, err := cli.ContainerExecAttach(ctx, execID, ec)
// error handling
defer atinfo.Close()
c = atinfo.Conn
one := make([]byte, 1)
_, err = c.Read(one)
if err == io.EOF {
println("Connection closed")
}
This will wait until the command execute complete
ExecConfig is set to
ec.Detach = false
ec.Tty = false
ec.AttachStdout = true

Corona sdk random text

I`m have a problem because when i touch my button sometimes not appear my text... (Sorry for my English!)
Code:
function randomText(event)
display.remove(mmDis)
local a = {"Cristiano ronaldo jest najlepszy!","messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"}
com = (a[math.random(1,#a)])
local mmDis = display.newText(tostring(com),
display.contentWidth*0.57, display.contentHeight*0.7,
display.contentWidth*0.9, display.contentHeight*0.8, "Impact", 30)
mmDis.y=20
mmDis.x=190
mmDis:setFillColor(0, 0, 0, 1)
mmDis.anchorY = 0
end
play:addEventListener ("tap", randomText )
end
end
play:addEventListener( "touch", object )
Make sure you are localizing your variables properly. You need to declare "mmDis" outside your function, and then do not localize it inside the function. Something like this
local mmDis* -- this will ensure code from here on out all use the SAME "mmDis"
function randomText(event)
display.remove(mmDis)
local a = {"Cristiano ronaldo jest najlepszy!","messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"}
com = (a[math.random(1,#a)])
-- NOTICE how I removed the local keyword below.
-- This will ensure your code is talking about the same "mmDis"
-- you declared before your function
mmDis = display.newText(tostring(com),
display.contentWidth*0.57, display.contentHeight*0.7,
display.contentWidth*0.9, display.contentHeight*0.8, "Impact", 30)
mmDis.y=20
mmDis.x=190
mmDis:setFillColor(0, 0, 0, 1)
mmDis.anchorY = 0
end
play:addEventListener ("tap", randomText )
end
end
play:addEventListener( "touch", object )
Ultimately, the problem you were having is that you were not removing the old text off the screen because mmDis was localized inside the randomText function. Make sure you localize your variables with proper scope. Here's a good read about it http://lua-users.org/wiki/ScopeTutorial
local mmDis
function randomText(event)
if event.phase == "began" then
if mmDis then
display.remove(mmDis)
end
local a = {"Cristiano ronaldo jest najlepszy!","messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"}
local com = a[math.random(1,#a)]
mmDis = display.newText(tostring(com),
display.contentWidth*0.57, display.contentHeight*0.7,
display.contentWidth*0.9, display.contentHeight*0.8, "Impact", 30)
mmDis.y=20
mmDis.x=190
mmDis:setFillColor(0, 0, 0, 1)
mmDis.anchorY = 0
end
end
play:addEventListener ("tap", randomText )
end
end
play:addEventListener( "touch", object )
Try this and see.

Resources