Running sysinternals strings.exe command in Jenkins batch command hangs - windows

I have a windows batch command in Jenkins as a build step, and I'm doing this:
CMD /C strings.exe a.bin
And it just sits there and spins forever. I cannot get it to work. I have put it in a batch file, I have tried running it with start, nothing seems to work. How do I get this to work?

Related

Execute WIndows bat file in Jenkins

I am using Jenkins 2.46.1
I have a build pipeline plugin installed and I want to execute a Windows batch file in it. The batch file should execute in a new command window and not on jenkins console output. I give the below Jenkins pipeline groovy script:
node {
stage 'Init'
bat '''
call C:\\myprj\\mybat.bat stop
EXIT /B 0
'''
stage 'Deploy'
bat '''call C:\\myprj\\mybat.bat'''
}
In the init stage, I want to kill the process if it is already open and in stage deploy it should open a new command window and run my batch file.
The problem is that the above does not work. The build is succesful but no command window opens up. Pls suggest
Technically, to do what you're asking you should be able to run
bat 'start cmd.exe /c C:\\myprj\\mybat.bat'
This will launch a new command windows (cmd.exe) and run the batch file given. Depending how your Jenkins slave is running you may not see anything. (eg if it's running as a windows service or different user, you won't see anything)
Alternative solution if the agent is running in a service and you would like to get output:
bat(readFile("mybat.bat"))
Note: The bat file will need to be in your workspace.
Additional Note: You are no longer running the bat file from its original location. Instead it is being run from a temp location created by the underlying durable task system. This means things like %~dp0 in your script are not going to return the paths you might expect.

run curl from windows task scheduler automatically

I have a simple one line bat file that runs a curl localhost:port. My curl.exe is in the same folder as the bat I don't have it installed globally. It runs fine if I double click it, it also runs fine if I right click in task scheduler and select run task. It also says it completes the "scheduled tasks" successfully but nothing happens (I'm sure of this as I'm checking data that should update if the script is run, and it doesn't happen under the scheduled/automatic scenarios). After reading lots of users issues I tried configuring in two ways (all on 5 minute updates):
Common Way
Action: Start a Program
Program/script: C:\p\updater.bat
Start in: C:\p\
Other Way
Action: Start a Program
Program/script: cmd
Add arguments: /c start "" "C:\p\updater.bat"
I have set permissions to the bat and the containing folder to allow all for all users/etc. Neither work when automatically triggered, neither error. I've tried in Server 2008 and Windows 10 (my OS) mode. Both work if I right click run task, neither automatically, any ideas?
Default working directory for scheduled script is %Windows%\system32. Try to add in first line to you updater.bat:
cd c:\p\
For diagnostic, you can add output redirect to you commands in bat file:
echo Script Started >> c:\p\log.txt
curl SomeCommand SomeCommand >>c:\p:\curloutput.txt
echo Script Ended >> c:\p\log.txt
and check files log.txt and curloutput.txt after execution of your script

How do I tell a windows batch script to execute the next line without waiting for the previous line to finish executing?

I'm setting up a .cmd script to be run on startup for a pseudo-server (It's actually a laptop, but that's irrelevant) to automatically launch pageant, load an SSH key, connect to an SSH server using Putty (Pageant would automatically authenticate with the key), then launch mIRC which in turn has a series of scripts setup to operate as an IRC bot and automatically connect to networks using putty as an SSH tunnel.
With that in mind, I have the below code in a startup.cmd file:
"C:\Program Files (x86)\PuTTY\pageant.exe" c:\Path\To\Private\Key.ppk
"C:\Program Files (x86)\PuTTY\putty.exe" -ssh user#host
"C:\Program Files (x86)\mIRC\mirc.exe"
EXIT
When I test run this file, the command prompt runs the first line, launches pageant, and then sits there and does nothing until I close pageant completely. I believe I have an idea on what the issue here is, but I can't find any information on how to resolve this in a batch file.
I do know on linux systems, if I were running a bash script to do something similar, I would want to have a & symbol at the end of each line to tell it to run the next command without waiting for the previous command to finish executing. I did try that in the batch script in the off chance that would work (It didn't).
For those who may ask, this is on Windows 8.1 64 bit. The user running this script is not an administrator.
I can't comment to expand on Squashman's suggestion, so let me answer here.
In your case, if you only want to have Pageant running in the background, without interacting with it, I think it's best to run:
START "" /B <your command>
The /B parameter will spawn the process without launching a new window for it, which seems like something you'd like to avoid (anyway, it's probably closest to the behaviour you can obtain in Linux with &).
Please note that if you close the window from which you spawned this process, it will terminate as well.

How to prevent batch file (.bat) from closing terminal when running commands?

On a Windows 7 machine if I run a PHPUnit Selenium command like this manually in the terminal:
phpunit --verbose --log-junit _selenium_tests\results\home.xml _selenium_tests\frontend\home.php
It spawns a browser and runs the test just fine. Then it outputs the following on the screen:
Time: 10 seconds, Memory: 3.50Mb
OK (1 test, 3 assertions)
And the terminal stays open.
Now if I copy and paste the exact command in an empty file and save it as test.bat and click it, it also runs the test. I can see the browser open and all tests run. Only problem is it closes the terminal prompt right after. So I can't see the above output.
An even bigger problem is, since it closes the terminal if I add more commands for other tests after that initial one they don't run.
I tried adding:
pause
at the end of the bat file but no luck, it still closes. Any idea how to prevent this and be able to run one command after another without the terminal ever closing?
Your question is similar to this one. Try using call in front of your command. If you run a .bat file from another .bat file and don't use call, control doesn't return to the first batch file, so pause doesn't get executed.
Try cmd /K phpunit --verbose --log-junit _selenium_tests\results\home.xml _selenium_tests\frontend\home.php
The /K option in cmd /K string Carries out the command specified by string but remains,see http://www.computerhope.com/cmd.htm
Also, I don't know the file type of the phpunit command you execute - I'm not familiar with selenium. If it is batch file (i.e. ends with .bat), you just can't call them from another batch file: everything below the call to the second batch file will never get executed.
You then need to use the CALL command. CALL Enables a user to execute a batch file from within another batch file, see http://www.computerhope.com/call.htm

Windows cmd: How to find and kill .bat file that was run and hidden with wscript?

I was playing with running a Turntable.fm bot, and I wanted to run it on my local machine's Nodejs installation, but not show the cmd window. So I ended up using a vbs script to hide the window:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
And then my .bat file looks like this:
.\node.exe .\Turntable-API\bots\carlin.js
That's it. Pretty simple. I created a shortcut file in Windows that then ran this:
C:\Windows\System32\wscript.exe "C:\ttbot\invisible.vbs" "C:\ttbot\ttbot.bat"
The issue now is that I have no idea how to find or kill the process that was started. When I try to look in my task manager, there's no wscript.exe, or cmd.exe, or node.exe, or invisible.vbs, or ttbot.bat running process of any sort. When I try running the .bat file in cmd, it doesn't close immediately, so I assume it needs manual shutdown of some sort. What should I do?
Try using Process Explorer, search for any of the processes that you mentioned above incase the processes are running under an existing process, find that, then you can kill yours.
If it doesn't show up in Process Explorer the likelyhood is the script isn't running or it ended after execution, possibly because of an error. Try running without the vbscript to make sure everything is ok.

Resources