How to pass WMIC parameters for WmiSetBrightness - wmi

The following line in PowerShell works (brightness changes to 30):
(Get-WmiObject -Namespace root\wmi -Class WmiMonitorBrightnessMethods).WmiSetBrightness(0,30)
However, when using WMIC I get the following error:
C:\>wmic /NAMESPACE:\\root\wmi PATH WmiMonitorBrightnessMethods CALL WmiSetBrightness Brightness=30 Timeout=0
Executing (WmiMonitorBrightnessMethods)->WmiSetBrightness()
ERROR:
Description = Invalid method Parameter(s)
What is the issue and how can I get this to work?

Turns out it works if I add a WHERE clause:
C:\>wmic /NAMESPACE:\\root\wmi PATH WmiMonitorBrightnessMethods WHERE "Active=TRUE" CALL WmiSetBrightness Brightness=30 Timeout=0
Executing (\\MY-HOSTNAME\root\wmi:WmiMonitorBrightnessMethods.InstanceName="DISPLAY\\...\\...")->WmiSetBrightness()
Method execution successful.
Not very intuitive, to say the least, but oh well.

Related

Execute command line in attribute

I want to generate MAC address and UUID in attribute and then pass the values to template.
something like this :
Attribute/default.rb:
default['libvirt']['xml_mac_Adrr'] = 'openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//''
default['libvirt']['xml_uuid'] = 'uuidgen virbr0'
Template/network.erb:
<uuid><%= node['libvirt']['xml_uuid'] %></uuid>
  <mac address='<%= node['libvirt']['xml_mac_Adrr']%>'/>
How can I do that?
UPDATE
I want to modify the default.xml network for the virtual network. Basically, we have to do it by virsh-net command
Now I want to use a template to pass UUID & MAC address values to XML file and modify it in guest machine.
this is my recipe:
template '/etc/libvirt/qemu/network/default.xml' do
source 'qemu-network.erb'
owner "root"
group "root"
mode "0644"
end
Yo can use backquotes to execute shell commands inside ruby and capture the response:
default['libvirt']['xml_mac_Adrr'] = `openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'`
default['libvirt']['xml_uuid'] = `uuidgen virbr0`
EDIT:
The second problem I see is that you have to use instance variables in the controller to share information with the view. So the best way would be:
#mac = `openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'`
#uuid = `uuidgen virbr0`
Then at view level you can use:
<uuid><%=#uuid %></uuid>
<mac address='<%=#mac %>'/>
Within chef relying on system commands should go through the shell_out method (which is included in the recipe dsl) to avoid some quirks when the DSL interpreter is run and getting methosd to clean up the ouput.
I'd go this way:
default['libvirt']['xml_mac_Adrr'] = Chef::ShellOut.new("openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'").stdout.chomp
default['libvirt']['xml_uuid'] = Chef::ShellOut.new('uuidgen virbr0').stdout.chomp
But this has a problem, at each run, a new mac address will be generated, so you should use normal and avoid redefining it, this is easiest moved into the recipe, following in recipe file before your template code should do:
node.normal['libvirt']['xml_mac_Adrr'] = shell_out("openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'").stdout.chomp unless node['libvirt'].includes?('xml_mac_Adrr')

How to unit test an Erlang function?

get_ue_supported_srvcc([]) ->
?SRVCC_3GPP_NONE_SUPPORT;
get_ue_supported_srvcc([#sip_contactV{extensionsP = EP} | T]) ->
case b2bLib:support_tags_to_value(EP) of
?SRVCC_3GPP_NONE_SUPPORT ->
get_ue_supported_srvcc(T);
Flag ->
Flag
end.
I want create a unit test for this function,
Here is my unit test case:
get_ue_supported_srvcc_test() ->
Contact =
[#sip_contactV{extensionsP =
[{"+sip.instance",
{quoted_string,"<urn:gsma:imei:35502406-005233-0>"}},
{"+g.3gpp.icsi-ref",
{quoted_string,"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"}},
"+g.3gpp.mid-call",
"+g.3gpp.srvcc-alerting",
"+g.3gpp.ps2cs-srvcc-orig-pre-alerting",
"video"]}],
?assertEqual(7, b2bAtcfLib:get_ue_supported_srvcc(Contact)).
But when I run it, I get this error:
======================== EUnit ========================
module 'b2bAtcfLib'
b2bAtcfLib_tests: get_ue_supported_srvcc_test (module 'b2bAtcfLib_tests')...*failed*
in function b2bLib:support_tags_to_value/1
called as support_tags_to_value([{"+sip.instance",{quoted_string,"<urn:gsma:imei:35502406-005233-0>"}},
{"+g.3gpp.icsi-ref",
{quoted_string,"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"}},
"+g.3gpp.mid-call","+g.3gpp.srvcc-alerting",
"+g.3gpp.ps2cs-srvcc-orig-pre-alerting","video"])
in call from b2bAtcfLib:get_ue_supported_srvcc/1 (src/b2bAtcfLib.erl, line 1735)
in call from b2bAtcfLib_tests:'-get_ue_supported_srvcc_test/0-fun-0-'/1 (test/unit/b2bAtcfLib_tests.erl, line 49)
in call from b2bAtcfLib_tests:get_ue_supported_srvcc_test/0
**error:undef
output:<<"">>
[done in 0.008 s]
=======================================================
The error means b2bLib:support_tags_to_value/1 is undef.
The define for this function b2bLib:support_tags_to_value:
support_tags_to_value(FieldStr) ->
lists:sum([Val || {Tag, Val} <- ?TAGLIST, lists:member(Tag, FieldStr)]).
The error is:
**error:undef
That means that the test is calling a function that's not defined. Either the module couldn't be found, or the module in question doesn't define a function with that name and arity.
The whole error message is a bit confusing. Now that we know that we got a "function undefined" error, we should be looking at this line:
in function b2bLib:support_tags_to_value/1
Even though it says that the error occurred "in" this function, this is the function that's undefined.
So either the test is run in such a way that it doesn't find the b2bLib module, or that module doesn't define a function called support_tags_to_value taking one argument. If it's the former, add -pa path/to/ebin to the Erlang command line in order to add the right directory to the code path.

Cakephp 3.0 Unit testing Issue

When i execute the plugins/SamplePlugin test cases, it executing perfect except the controller functions which are related to urls.
The test case function like
public function testIndex()
{
$this->get('/sample-plugin /mycontroller/index');
$this->assertResponseOk();
}
when i execute the above testcase the exception
There was 1 error:
1) SamplePlugin\Test\TestCase\Controller\MyControllerTest::test
Index
include(D:\xampp\htdocs\EATZ_V2_3.X\vendor\cakephp\cakephp\tests\test_app\config\routes.php): failed to open stream: No such file or directory
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:974
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:974
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:547
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:451
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:392
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:312
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:233
D:\xampp\htdocs\MyApp\plugins\SamplePlugin\tests\TestCase\Controller\MyControllerTest.php:29
D:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
D:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
FAILURES!
Tests: 30, Assertions: 42, Errors: 1.
please resove the issue.thanks in advance!!!
The error states that the routes.php file is missing in the folder config. Refer to the CakePHP 3 Documentation to create a meaningful routes.php.

Can't enable phar writing

I am actually using wamp 2.5 with PHP 5.5.12 and when I try to create a phar file it returns me the following message :
Uncaught exception 'UnexpectedValueException' with message 'creating archive "..." disabled by the php.ini setting phar.readonly'
even if I turn to off the phar.readonly option in php.ini.
So how can I enable the creation of phar files ?
I had this same problem and pieced together from info on this thread, here's what I did in over-simplified explanation:
in my PHP code that's generating this error, I added echo phpinfo(); (which displays a large table with all sort of PHP info) and in the first few rows verify the path of the php.ini file to make sure you're editing the correct php.ini.
locate on the phpinfo() table where it says phar.readonly and note that it is On.
open the php.ini file from step 1 and search for phar.readonly. Mine is on line 995 and reads ;phar.readonly = On
Change this line to phar.readonly = Off. Be sure that there is no semi-colon at the beginning of the line.
Restart your server
Confirm that you're phar project is now working as expected, and/or search on the phpinfo()table again to see that the phar.readonly setting has changed.
phar.readonly can only be disabled in php.ini due to security reasons.
If you want to check that it's is really not done using other method than php.ini then in terminal type this:-
$ php -r "ini_set('phar.readonly',0);print(ini_get('phar.readonly'));"
If it will give you 1 means phar.readonly is On.
More on phar.configuration
Need to disable in php.ini file
Type which php
Gives a different output depending on machine e.g.
/c/Apps/php/php-7.2.11/php
Then open the path given not the php file.
E.g. /c/Apps/php/php-7.2.11
Edit the php.ini file
could do
vi C:\Apps\php\php-7.2.11\php.ini
code C:\Apps\php\php-7.2.11\php.ini
[Phar]
; http://php.net/phar.readonly
phar.readonly = Off
; http://php.net/phar.require-hash
phar.require_hash = Off
Save
Using php-cli and a hashbang, we can set it on the fly without messing with the ini file.
testphar.php
#!/usr/bin/php -d phar.readonly=0
<?php
print(ini_get('phar.readonly')); // Must return 0
// make sure it doesn't exist
#unlink('brandnewphar.phar');
try {
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
} catch (Exception $e) {
echo 'Could not create phar:', $e;
}
echo 'The new phar has ' . $p->count() . " entries\n";
$p->startBuffering();
$p['file.txt'] = 'hi';
$p['file2.txt'] = 'there';
$p['file2.txt']->compress(Phar::GZ);
$p['file3.txt'] = 'babyface';
$p['file3.txt']->setMetadata(42);
$p->setStub('<?php
function __autoload($class)
{
include "phar://myphar.phar/" . str_replace("_", "/", $class) . ".php";
}
Phar::mapPhar("myphar.phar");
include "phar://myphar.phar/startup.php";
__HALT_COMPILER();');
$p->stopBuffering();
// Test
$m = file_get_contents("phar://brandnewphar.phar/file2.txt");
$m = explode("\n",$m);
var_dump($m);
/* Output:
* there
**/
✓ Must be set executable:
chmod +x testphar.php
✓ Must be called like this:
./testphar.php
// OUTPUT there
⚠️ Must not be called like this:
php testphar.php
// Exception, phar is read only...
⚠️ Won't work called from a CGI web server
php -S localhost:8785 testphar.php
// Exception, phar is read only...
For anyone who has changed the php.ini file, but just doesn't see any changes. Try to use the CLI version of the file. For me, it was in /etc/php/7.4/cli/php.ini
Quick Solution!
Check:
cat /etc/php/7.4/apache2/php.ini | grep phar.readonly
Fix:
sed -i 's/;phar.readonly = On/;phar.readonly = Off/g' /etc/php/7.4/apache2/php.ini

Selenium IDE - storedVars exception

I am using selenium IDE and i want to store a data:
storeEval | storedVars['varRate'].match(/EUR.\d+.\d+/); |rate01
echo |${rate01}
storeEval |storedVars['rate01'].match(/\d+.\d/);|rate
The first one works just fine but second one throws an exception:
[error] Threw an exception: storedVars.rate.match is not a function
Can you please help me? Thank you.
The problem was that match is a string method and I didn't use it correctly. First result was an array so i added another comand to cast it to string:
store | ${rate01} | rate02 followed by
storeEval | storedVars['rate02'].match(/\d+.\d/);| rate