I was trying to make some post build events depends on configuration. However, the if condition failing, either with code 255 or 9009. Even I removed all the code, just using simple one now.
if "$(ConfigurationName)" == "Release" ( CALL "notepad" )
else ( CALL "mspaint" )
Result 9009
if "$(ConfigurationName)" == "Release" ( )
else ( )
Result 255
Also tried
if "$(ConfigurationName)" == "Release" ( echo "test" )
else ( echo "test2" )
Result again 9009
I do not understand why its failing with 9009 when I use any command ? and even with 255 when there is nothing.
I have checked the code, it does substitute $(ConfigurationName).
The reason it is failing with error code 9009 is because you have not structured the if-else
statement correctly. You cannot put else on the beggining of the line (the rules are the same
as for batch files), use the following method:
if "$(ConfigurationName)" == "Release" (
CALL "notepad"
) else (
CALL "mspaint"
)
As for the other example, it fails with error code 255 because you did not put any statement
in the brackets (it is illegal).
Related
I'm writing a script in which i will verify if some elements are present and others are not.
For the ones which are present I'm using:
verify do
assert_include(
#driver.find_element(
:css,
"div.launchpadMain > section:nth-of-type(4) > div.launchpadCategoryBody > a:nth-of-type(2)"
).text,
"shiftplan"
)
end
Example for a element which is not present... I'm trying:
verify do
element_not_present(
#driver.find_element(:css, "button.btn.btn-icon.pull-right > i")
)
end
---> This is not working though. Which command can I use to make a verification if the element/object is present or not? In this case the element/object is a trash icon.
Switch to the group collector find_elements (plural), to stop it returning an exception, then assert it's empty.
verify do
assert_empty(
#driver.find_elements(:css, "button.btn.btn-icon.pull-right > i").size
)
end
find_elements: http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium%2FWebDriver%2FFind:find_elements
I am executing some sql queries using OSQL through inno setup. I am using following code to run OSQL. This is just for example purpose
SQLQuery:= '"EXEC sp_addserver ''PCNAME'';"';
Param:= '-S(local) -Usa -Psa -Q ' + SQLQuery;
Exec('osql.exe', Param, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
This works fine. The problem is ResultCode value is always 0. Even if the query does not get executed. For example if I try same query like below where I pass in an invalid stored procedure name the ResultCode is still 0.
SQLQuery:= '"EXEC sp_invalidname ''PCNAME'';"';
Param:= '-S(local) -Usa -Psa -Q ' + SQLQuery;
Exec('osql.exe', Param, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Why don't this return me a proper code. If I run the second query in management studio I get an error like this
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'sp_invalidname'
Here return code is 2812. Why dont I get this when I run it through inno. What do I need to do to get this error code in inno?
Thanks to TLama, I updated my code as below and its working now. I had to add -b command line parameter and now it returns 1 if the command fails.
-b
Specifies that osql exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 11 or greater; otherwise, the value returned is 0. Microsoft MS-DOS batch files can test the value of DOS ERRORLEVEL and handle the error appropriately.
I updated my code as below.
Param:= '-S(local) -Usa -Psa -b -Q ' + SQLQuery;
Its explained in the documentation.
let's say i have an executable file stored in c:\my directory\my file.exe that i would like to initiate near the beginning of my R script, and then terminate near the end of my R script. what are some clean ways do this on a windows platform?
i am aware of R commands like shell and shell.exec, but it's not clear to me that these will allow a clean capture of the process id to then use something like the pskill function. it's also not clear if it makes more sense to run this executable through some sort of pipe conection - or how that pipe would work. this particular executable should be included in my windows PATH as a system variable, so it's conceivable that the system function might be of value here as well.
additional clarification: capturing the process id might be important, because (at least for me) this will be used on a database server's executable -- if multiple database servers are currently running on the same machine, the process shouldn't kill all of them - just the one initialized at the start of the R script.
for extra credit: let's say c:\my directory\my file.exe should be called by actually executing another file - c:\my directory\another file.bat - but it's my file.exe that needs to be killed at the end of the R script.
drawing on the other two answers received, this technique seems like a reasonable way to accomplish the stated goal..
# specify executable file
exe.file <- "C:\\Users\\AnthonyD\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
# capture the result of a `tasklist` system call
before.win.tasklist <- system2( 'tasklist' , stdout = TRUE )
# store all pids before running the process
before.pids <- substr( before.win.tasklist[ -(1:3) ] , 27 , 35 )
# run the process
shell.exec( exe.file )
# capture the result of a `tasklist` system call
after.win.tasklist <- system2( 'tasklist' , stdout = TRUE )
# store all tasks after running the process
after.tasks <- substr( after.win.tasklist[ -(1:3) ] , 1 , 25 )
# store all pids after running the process
after.pids <- substr( after.win.tasklist[ -(1:3) ] , 27 , 35 )
# store the number in the task list containing the PIDs you've just initiated
initiated.pid.positions <- which( !( after.pids %in% before.pids ) )
# remove whitespace
after.tasks <- gsub( " " , "" , after.tasks )
# find the pid position that matches the executable file name
correct.pid.position <-
intersect(
which( after.tasks %in% basename( exe.file ) ) ,
initiated.pid.positions
)
# remove whitespace
correct.pid <- gsub( " " , "" , after.pids[ correct.pid.position ] )
# write the taskkill command line
taskkill.cmd <- paste( "taskkill" , "/PID" , correct.pid )
# wait thirty seconds (so the program fully loads)
Sys.sleep( 30 )
# kill the same process that was loaded
system( taskkill.cmd )
You could use system function:
system("Taskkill /IM myfile.exe /F")
edit: This worked in my computer with Windows 7 (tested with killing skype.exe).
In the past, I used psKill. It is really powerful and maybe dangerous. You kill multi-procees even ina remote computer. I think you konw we must be extremely careful when we want to kill brutally process.
Download the tool , unzip and copy in a known path.
First time you launch is asking for liscence..You launch it from the cmd once and you agree.
Then you use somthing like this
process_name <- 'your_process_name'
system(paste(path_to_pskil,'pskill ',process_name,sep=''),intern=T)
For example to kill all chrome instances, you do this
system('c:/temp/pskill chrome',intern=T) !!
EDIT
Assuming you have multi process with the same name. You can use pslist to list all process with this name. Find the id of the process you want to kill according to its elapsed time, then call pskill by id.
For example here I want to kill , the last launched chrome process
my.process <- system('c:/temp/pslist chrome ',intern=T)[-c(1:8)]
my.process
[1] "chrome 3852 8 38 1052 141008 0:01:58.108 1:43:11.547"
[2] "chrome 5428 8 11 202 220392 0:02:08.092 1:43:11.359"
[3] "chrome 6228 8 9 146 73692 0:01:58.467 1:43:00.091"
[4] "chrome 6312 6 9 130 45420 0:00:08.704 1:17:30.153"
[5] "chrome 360 6 9 127 29252 0:00:01.263 0:57:01.084"
[6] "chrome 5032 6 9 126 29596 0:00:00.717 0:31:39.875"
[7] "chrome 2572 8 9 120 23816 0:00:00.452 0:19:10.307"
## ids are orderd according to the elpased time
## I use tail to get the last one
## some regular expression to get the id from the string
## mine is ugly but I am sure you can do better.
id <- substr(gsub("([^[:digit:]]*)", "", tail(my.process,1)),1,4)
system(paste('c:/temp/pskill ', id) ,intern=T)
within af:resource component in javascript, use of the && for comparison throws the following error:
Expected name instead of &
The second ampersand is highlighted with a wavy red underscore when this error is thrown.
The sample code is shown below.
blnTargetRowReady = (targetIndex==1 && targetDestinationComponent.getValue()==null && targetOriginComponent.getValue()==null && targetSelectComponent.checked==false && targetDateComponent.getValue()!=null);
I notice when i subsitute the && with || this error does not occur.
Does anyone know why this error occurs on the page. The page runs fine when run in the browser, ie with the ampersand, but in JDeveloper the relevant page shows up with an error.
Any guidance you can provide i would appreciate it.
In your code, try to replace each ampersand with &
blnTargetRowReady = (targetIndex==1 && targetDestinationComponent.getValue()==null && targetOriginComponent.getValue()==null && targetSelectComponent.checked==false && targetDateComponent.getValue()!=null);
I tried this, but it doesn't seem to work
subtest 'catalyst scripts that should be executable' => sub {
plan({ skip_all => 'skip failing executable tests on windows' }) if $^O eq 'MSWin32';
my $should_exec = [ #{ $dzpcs->scripts } ];
foreach ( #{ $should_exec } ) {
ok ( -x $_ , "$_" . ' is executable' );
}
};
Here's what I got in my cpants report.
plan() doesn't understand HASH(0x286f4cc) at t/02-MintingProfileCatalyst.t line 46.
# Child (catalyst scripts that should be executable) exited without calling finalize()
# Failed test 'catalyst scripts that should be executable'
# at C:/strawberry/perl/lib/Test/Builder.pm line 252.
# Tests were run but no plan was declared and done_testing() was not seen.
So I guess it's not a hash, not really sure what it is then... what's the cleanest way to make this work? (p.s. I can't test win32, I only have my Linux box)
plan takes two parameters, not a hashref:
plan( skip_all => 'skip failing executable tests on windows' ) if $^O eq 'MSWin32';
Not everything uses Moose. ;-)
Note: for testing purposes, you could change eq to ne, so it will skip the tests on your Linux box. Just remember to change it back afterwards.