Perl Net::Appliance::Session waitfor? - perl

I have a problem with Net::Appliance::Session. I created a session, executed my command. After execution it prompts me some question (yes/no). I want to answer it but didn't find a way how to do it. Below you can see my trials:
$session->cmd($command);
$session->waitfor(Match=>'/.*yes*/');
$session->print("no");
$session->waitfor(Match=>'');
$session->print("y");
I don't know where is the problem. Accoding to CPAN documentations Net::Telnet have the method waitfor. But Session documentation tells that we can use waitfor(). Another thing said there is that the method "cmd" have a member Match which includes all the features of waitfor(). So I changed my code like below:
$session->cmd($command, Match=>'/.*yes*/');
$session->print("no");
Executing this reports below error:
Odd number of elements in hash assignment at
/usr/lib/perl5/vendor_perl/5.8.8/Net/Appliance/Session.pm line 245.
Is there any idea how can I do that? And why am I getting this error message?
Thanks in advance..

From the Net::Appliance::Session page at meta::cpan
To handle more complicated interactions, for example commands which prompt for confirmation or optional parameters, you should use a Macro. These are set up in the phrasebook and issued via the $s->macro($name) method call. See the Phrasebook and Cookbook manual pages for further details.
So you set up a macro (scripted call and response) in a phrasebook, and then tell your session to use that macro.

Related

mysqli_query($conn, $sql) On adding this, giving an error of 500 INTERNAL SERVER ERROR, No detailed error shown [duplicate]

In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:
Fatal error: Call to a member function bind_param() on a non-object in...
Here is the code:
global $mysqli;
$stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?");
$stmt->bind_param('i', $cur_id);
$stmt->execute();
$stmt->bind_result($uid, $desc);
To check my query, I tried to execute the query via control panel phpMyAdmin and the result is OK.
TL;DR
Always have mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); in your mysqli connection code and always check the PHP errors.
Always replace every PHP variable in the SQL query with a question mark, and execute the query using prepared statement. It will help to avoid syntax errors of all sorts.
Explanation
Sometimes your MySQLi code produces an error like mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given..., Call to a member function bind_param()... or similar. Or even without any error, but the query doesn't work all the same. It means that your query failed to execute.
Every time a query fails, MySQL has an error message that explains the reason. In the older PHP versions such errors weren't transferred to PHP, and all you'd get is a cryptic error message mentioned above. Hence it is very important to configure PHP and MySQLi to report MySQL errors to you. And once you get the error message, fixing it will be a piece of cake.
How to get the error message in MySQLi
First of all, always have this line before MySQLi connect in all your environments:
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
After that, all MySQL errors will be transferred into PHP exceptions. An uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. And the stack trace will lead you to the exact spot where the error occurred.
How to get the error message from PHP
Here is a gist of my article on PHP error reporting:
Reporting errors on a development and live servers must be different. On the development server it is convenient to have errors shown on-screen, but on a live server error messages must be logged instead, so you could find them in the error log later.
Therefore, you must set corresponding configuration options to the following values:
On a development server
error_reporting should be set to E_ALL value;
log_errors should be set to 1 (it is convenient to have logs on a development PC too)
display_errors should be set to 1
On a production server
error_reporting should be set to E_ALL value;
log_errors should be set to 1
display_errors should be set to 0
After that, when MySQL query fails, you will get a PHP error that explains the reason. On a live server, in order to get the error message, you'll have to check the error log.
In case of AJAX call, on a dev server open DevTools (F12), then Network tab. Then initiate the request which result you want to see, and it will appear in the Network tab. Click on it and then the Response tab. There you will see the exact output. On a live server check the error log.
How to actually use it
Just remove any code that checks for the error manually, all those or die(), if ($result), try..catch and such. Simply write your database interaction code right away:
$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();
Again, without any conditions around. If an error occurs, it will be treated like any other error in your code. For example, on a development PC it will just appear on-screen, while on a live site it will be logged for the programmer, whereas for the user's convenience you could use an error handler (but that's a different story which is off topic for MySQLi, but you may read about it in the article linked above).
What to do with the error message you get
First of all you have to locate the problem query. The error message contains the file name and the line number of the exact spot where the error occurred. For the simple code that's enough, but if your code is using functions or classes you may need to follow the stack trace to locate the problem query.
After getting the error message, you have to read and comprehend it. It sounds too obvious if not condescending, but learners often overlook the fact that the error message is not just an alarm signal, but it actually contains a detailed explanation of the problem. And all you need is to read the error message and fix the issue.
Say, if it says that a particular table doesn't exist, you have to check spelling, typos, and letter case. Also you have to make sure that your PHP script connects to a correct database
Or, if it says there is an error in the SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error message.
If you don't understand the error message, try to google it. And when browsing the results, stick to answers that explain the error rather than bluntly give the solution. A solution may not work in your particular case, but the explanation will help you to understand the problem and make you able to fix the issue by yourself.
You have to also trust the error message. If it says that number of tokens doesn't match the number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.
A list of things you should never ever do in regard of error reporting
Never use an error suppression operator (#)! It makes a programmer unable read the error message and therefore unable to fix the error
Do not use die() or echo or any other function to print the error message on the screen unconditionally. PHP can report errors by itself and do it the right way depends on the environment - so just leave it for PHP.
Do not add a condition to test the query result manually (like if($result)). With error exceptions enabled such condition will just be useless.
Do not use the try..catch operator for echoing the error message. This operator should be used to perform some error handling, like a transaction rollback. But never use it just to report errors - as we learned above, PHP can already do it, the right way.
P.S.
Sometimes there is no error, but no results either. Then it means, there is no data in the database to match your criteria. In this case you have to admit this fact, even if you can swear the data and the criteria are all right. They are not. You have to check them again.
I've got an article that can help in this matter, How to debug database interactions. Although it is written for PDO, the principle is the same. Just follow those instructions step by step and either have your problem solved or have an answerable question for Stack Overflow.

'rasa shell' does not intiate a chat session as expected

The command 'rasa shell' is supposed to start a chat session in the terminal itself upon its execution according to the documentation. But in my case, it's acting as given in the below image.
But the output is supposed to be a 2-way communication between the bot and the user as given below.
Your input -> hi
<Bot's response to 'hi'>
Your input -> something
<Bot's response to 'something'>
May I know what the reason for the above matter is? (Please note that I noticed a similar question to mine here). Since I found it not descriptive enough, I have posted this question.
Check if:
There aren't any redundant intent names in domain.yaml file.
There aren't any missing quotation marks in responses.

Powershell - The Parameter "XXXX" is declared in parameter-set "__AllParameterSets" multiple times

First of all, i'm sorry if this question has been posted before.
I couldn't seem to find and answer we could work with, so here goes..
Backstory:
Every 90 days all password of the NT-accounts will expire.
The office staff gets a notification when they're signing in into Windows 10.
However our iPad users (salesmen and technicians who are on the road) don't get a notification about the expiration.
They use an app which requires a NT-account to sign into our sales system.
Now we've found a Powershell script which would e-mail the user about the expiration of his password, but unfortunately we keep getting the following error:
"The parameter "testing" is declared in parameter-set "__AllParameterSets" multiple times."
As we do not have any Powershell programming skills, we have no idea what going wrong in the script.
Could you guys help us?
The following script is being used (ofcourse edited with our SMTP server and e-mail addresses).
https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27
Much obliged :-)
the code you 1st linked to never, EVER mentions parameter sets. not once. [grin]
the code in your 2nd link mentions it # 106 = __AllParameterSets.
that it IS NOT a parameter set attribute, but is some "other thing". it looks like a call to something in python.
there is no other mention anywhere in your linked code of that __AllParameterSets thing.
so, the fix is to remove it OR to rename it something that does not use a powershell keyword. [grin]

Why doesn't elapsed_time() work from log_message() even if called from post_system hook?

If I try to log benchmark->elapsed_time() in post_system hook, it just logs {elapsed_time} as if I called it from a controller.
CodeIgniter documentation says:
"post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser."
It also says you are supposed to echo the elapsed_time() in a view to show it to the user, but... how is it possible that elapsed_time() is still being calculated after sending the finalized data to the browser?
I feel being lied to.
People keep saying I should use my own marks and get the difference, but that's not the same as using this...
Turns out the documentation also says:
"If the first parameter is empty this function instead returns the {elapsed_time} pseudo-variable. This permits the full system execution time to be shown in a template. The output class will swap the real value for this variable."
I went to the Output class and found the 2 marks it is using: total_execution_time_start and total_execution_time_end and I can use those in the post_system hook.

How to create an AS/400 command with mutually exclusive parameters?

I need to create an AS/400 command. Based on the requirement, it has two parameter, say A and B, which cannot be filled in the same time. Both will be displayed when F4 is pressed to prompt, but only one can be filled at a time. If both are filled an error message should appear saying this is invalid. Can someone tell me how to create a command like this? What do I need to specify in the CMD source to achieve it?
Use the DEP command definition statement to control the parameters.
CMD PROMPT('TEST')
PARM KWD(A) TYPE(*CHAR) PROMPT('A')
PARM KWD(B) TYPE(*CHAR) PROMPT('B')
DEP CTL(*ALWAYS) PARM(A B) NBRTRUE(*EQ 1)
The CMD source only has rudimentary ability to perform validity checking. Typically, end user business rules are enforced by a validity checking program. See CRTCMD VLDCKR(). The VCP is very similar to the CPP, except if the command fails validity checking, your VCP sends a *DIAG message to the caller with the details of the reason, and a CPF0002 *ESCAPE message to the caller to tell it the command did not run.