Not able to pass the command-file in Jprofiler - jprofiler

I tried to automate the JProfiler in offline mode to connect to a running JVM using below batch script. I am not able to pass command-file which would take the inputs to the JProfiler. I am still unsure what format do I need to pass to the JProfiler. I tried passing as text and File formats but no luck.
BatchScript.bat
#echo off
TITLE "Profiling an application using JPofiler"
echo ***********Running JProfiler in non-interactive mode*****************
set "JPROFILER_HOME=C:\dev\jprofiler11"
set JPROFILER_CONFIG_FILE_LOCATION=C:\dev\profiler_start_script\config.xml
"%JPROFILER_HOME%"\bin\jpenable.exe --offline --id=116 --config=%JPROFILER_CONFIG_FILE_LOCATION%
if %ERRORLEVEL% NEQ 0 (
set ERROR= Jpenable is not able to profile the selected JVM, check JPROFILER_HOME and JPROFILER_CONFIG_FILE_LOCATION is set to correct location.
goto endError)
set /p PID=Enter the process id of the JVM:
SET "JPCONTRL=%JPROFILER_HOME%\bin\jpcontroller.exe"
"%JPCONTRL%" -n --non-interactive -f **--command-file=C:\dev\profiler_start_script\commands** %PID%
goto end
:endError
echo Error: %ERROR%
:end
endlocal
Commands
startCPURecording true
saveSnapshot C:\dev\build\trunk\WBScheduler\snapshot.jps
stopCPURecording
Can anyone tell me what format do i need to send the inputs file to the JProfiler?
I am using Jprofiler 11+ version.

The arguments to jpcontroller.exe should be
-n --non-interactive -f C:\dev\profiler_start_script\commands %PID%
Also, the commands should include a sleep, otherwise there will be no data in the snapshot:
startCPURecording true
sleep 10
stopCPURecording
saveSnapshot C:\dev\build\trunk\WBScheduler\snapshot.jps
Just tested this with JProfiler 11.1.4. If your problem persists, please include the error message. Also try to invoke the commands manually.

Related

Intellij Idea - ignoring non-zero exit code of external tool

I'm using external tool to run fuser -k 1099 command before actually launching my run configuration
But if external tool returns non-zero status, build configuration stops. That is perfectly correct, but I can not find any way to ignore failure. If it was a plain bash, I'd do something like fuser -k 1099 || true. But at Idea, that seems to be not possible
Any ideas?
You can use /bin/bash as the program and the following as the arguments:
-c 'fuser -k 1099'; true
This way the exit code of the tool will be always zero.
Correct answer was not working for me (see my comment under it) I then found a solution that is to create a script that exits with 0, here under windows (let us call it KillMyExeNoError.bat):
taskkill /IM my.exe /F
exit /B 0
Then put C:\Path\To\KillMyExeNoError.bat in Program and leave Arguments empty.
Maybe under Linux you need to put bash in Program and /path/to/script.sh in Arguments.
Not the best solution since it would be good not to have to create a separate script but at least it works.

How to run a command in vmware using vmrun, command is (echo %PROGRAMFILES%)

How to run a command in vmware using vmrun, command is (echo %PROGRAMFILES%) on the guest machine..
and the guest machine should return a value of the command result... how to do this??? please suggest
I needed to do something similar and found this unanswered question. Here's my solution.
#ECHO OFF
REM Set up abbreviations that we'll be using a lot.
SET VMRUN="C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T ws -gu Administrator -gp password
SET VMX="C:\Users\whoever\Documents\Virtual Machines\Windows\Windows.vmx"
SET GUEST_COMSPEC="C:\WINDOWS\system32\cmd.exe"
REM Tried to do this in one line, but couldn't figure out the quoting.
%VMRUN% CreateTempfileInGuest %VMX% >%TEMP%\GuestTmp.txt || GOTO :CantCreate
FOR /F "delims=;" %%F IN ( %TEMP%\GuestTmp.txt ) DO SET GTEMP=%%F
REM The batch file is a one-liner that echos the variable into a file.
REM It could be generated dynamically and copied to the guest
REM but I didn't want to complicate things any further.
%VMRUN% runProgramInGuest %VMX% %GUEST_COMSPEC% "/c C:\echo-ProgramFiles.bat %GTEMP%"
%VMRUN% CopyFileFromGuestToHost %VMX% %GTEMP% %TEMP%\GuestOut.txt
%VMRUN% DeleteFileInGuest %VMX% %GTEMP%
REM Do something with the result and delete the temp files.
TYPE %TEMP%\GuestOut.txt
DEL %TEMP%\GuestOut.txt %TEMP%\GuestTmp.txt
GOTO :EOF
:CantCreate
REM Provide details on any problems.
TYPE %TEMP%\GuestTmp.txt 1>&2
DEL %TEMP%\GuestTmp.txt
EXIT 100
And here's the batch file on the guest host. As you can see, it's pretty simple. I couldn't get redirection to work in runProgramInGuest (probably didn't experiment enough)
so I just pass the file as a command line argument.
#echo %PROGRAMFILES% >%1
Have a look at the vmrun commands here. You need the Guest OS Command runScriptInGuest.
I have not checked the command , but it should look like this. Please verify it.
vmrun -T server -h https://xps:8333/sdk -u user -p mypassword -gu administrator -gp guestpaswd
runScriptInGuest "[Vol1] win2008-1/win2008-1.vmx" "echo %PROGRAMFILES%"
I had to use runProgramInGuest
capture the output to a file
copy the file back to my host and use it
Thats the soln I used.

Passing CMD Results to Variable in a Batch File

I am trying to install an application and a group of services using PSTools, but I want to take into account that the computer I am trying to connect to may be turned off or on a different network, which is not reachable from the internal network.
Basically if the machine is not able to be accessed through the admin share, this is the message that I am getting:
Couldn't access MachineName:
The network path was not found.
Make sure that the default admin$ share is enabled on MachineName.
This is the syntax I am using to try to capture the "Error Message" and then report back that if installation was successful or not (depending on if it can contact the machine)
#echo off
set /p name=What is the machine name?:
psexec.exe \\%name% -u *useraccount* -p *password* \\ServerName\installation.bat
FOR /F "tokens=*" %%A IN ('COMMAND ^| FIND "Couldn't access"') DO SET Error=%%A
If "%Error%"=="Couldn't access"
ECHO Installation Failed.
Else
ECHO Installtion complete.
Pause
exit
Currently it hangs right at the point it's defining the Error Variable. Can't quite figure out what I am going wrong here.
'COMMAND ^| FIND "Couldn't access"' opens a command shell, which is why it hangs. It will not proceed until that shell is exited.
You will need to look at redirecting the error messages to another file. 2>Errors.txt on the psexec line will give you a file to search in the next line.
this will make the batch file look something like this:
#echo off
set /p name=What is the machine name?:
psexec.exe \\\%name% ... \\\ServerName\installation.bat 1>Error.txt 2>&1
for /f "tokens=*" %%A in ('FIND /i error.txt "Couldn't Access"') do SET Error=%%A
If not x%ERROR:Couldn=%==x%ERROR% (
ECHO Installation Failed.
) Else (
ECHO Installtion complete.
)
Pause
exit
(Also, notice the use of brackets to make a multi line IF)
the check for if will see if Couldn is part of the string, as a direct comparison will not work, as you would have to check against the whole string including the machine name

Is there a way to configure PuTTY or other terminal to flash the taskbar on next output to stdout?

I'm specifically looking for a solution for PuTTY but also interested for other terminal emulators, like Gnome Terminal.
My thought is it would be useful if I start a tar zxvf to be able to set a trigger on the terminal emulator, minimize it, and on next output to stdout/stderr I get a notification in the task bar that the command has finished.
This works for me:
echo -e "\a"
Then update your PuTTY session to use the Visual Bell, and set "Taskbar/caption indication on bell" to Flashing or Steady.
Then run this command after your tar completes:
tar xvzf file ; echo -e "\a"
Here is a screenshot: Save these settings as the default settings and/or the sessions' settings you have

How to check if a particular command line is running in cmd propmt

I desperately need help to create a vb / dos code which will do the following:
Check if a command prompt window is running with the following command: mgms A1 (mgms is a custom command)
If it is running, exit.
If it is not running, start cmd prompt and run the command , exit
Thanks a lot for your help!
The Windows cmd.exe batch language is horrible, but you should be able to put this in a batch file and get it working:
tasklist /FI "IMAGENAME eq mgms.exe" 2>&1 | findstr /B "INFO: No tasks running" > tmp
for /F "delims=" %x in (tmp) do mgms A1
You may need to further check that the command-line arguments to mgms.exe match what you expect -- have a look at the help for tasklist.exe and findstr.exe. Both programs are both standard in WinXP Pro and up, I believe. If you don't have them, I'm sure you can find them or (near) equivalents on the web.