how to grep a string from file in skill file(.il) - cadence

sumfile = simplifyFilename("getWorkingDir/perc.sum")
sumpath = strcat("grep -r "RUN COMPLETED" " sumfile " > out.txt")
print(sumpath)
system(sumpath)
am getting error as
Error lineread/read: syntax error encountered in input

You should escape quote marks. See below
strcat("grep -r \"RUN COMPLETED\" " sumfile " > out.txt")

Related

QProcess does not work if the path in argument list has a whitespace

I want to execute following command using QProcess, that works in cmd already if executed:
C:\\myApplication\\tools\\dcmodify.exe -v -ie -gin -nb -ma (0010,0010)=TestedData "C:\Users\user.name\Documents\My Tools Data\Temp\Demo Phantom Skin\dicom\*"
The first argument, which gives the path of the executable is defined as a QString:
QString srcToolPath = QDir::toNativeSeparators(QDir::cleanPath(qApp->applicationDirPath() + Constants::TOOLS_PATH + QDir::separator() + toQString("dcmodify.exe")));
The argument list and path, where the executable should be executed, is defined as a QStringList:
QString dstDicomPath = QDir::cleanPath(Utilities::getTempPath() + QDir::separator() + toQString("Anon_") + QDateTime::currentDateTime().toString(Constants::DETAILED_DATE_TIME_FORMAT)) + QDir::separator();
QStringList argumentList;
argumentList <<
toQString(" -v") <<
toQString(" -ie") <<
toQString(" -gin") <<
toQString(" -nb") <<
toQString(" -ma (0010,0010)=TestedData") <<
toQString(" \"") + QDir::toNativeSeparators(dstDicomPath) + toQString("*\"");
and the process is started:
QProcess anonymizerProcess;
anonymizerProcess.start(srcToolPath, argumentList);
Since the dstDicomPath contains some whitespaces, I added quotes around it. Although the command is executed, somehow I don't get the result like in cmd. What I am doing wrong with dstDicomPath string?
OK, there are multiple unknowns, for example what toQString() does in your code, but nevermind. Let's start with the assumption that this command is correct and would work if you called it from the command line:
C:\myApplication\tools\dcmodify.exe -v -ie -gin -nb -ma (0010,0010)=TestedData "C:\Users\user.name\Documents\My Tools Data\Temp\Demo Phantom Skin\dicom\*"
now lets have a look at what QProcess::splitCommand() returns (note that I escaped the backslashes and quotes in the command by prepending backslash):
QString cmd= "C:\\myApplication\\tools\\dcmodify.exe -v -ie -gin -nb -ma (0010,0010)=TestedData \"C:\\Users\\user.name\\Documents\\My Tools Data\\Temp\\Demo Phantom Skin\\dicom\\*\"";
qDebug() << QProcess::splitCommand(cmd);
It displays
("C:\\myApplication\\tools\\dcmodify.exe", "-v", "-ie", "-gin", "-nb", "-ma", "(0010,0010)=TestedData", "C:\\Users\\user.name\\Documents\\My Tools Data\\Temp\\Demo Phantom Skin\\dicom\\*")
... and this is exactly what you need to pass to the program and arguments for calling QProcess::start(). Hence:
auto program = QString("C:\\myApplication\\tools\\dcmodify.exe");
auto arguments = QStringList() << "-v" << "-ie" << "-gin" << "-nb"
<< "-ma" << "(0010,0010)=TestedData"
<< "C:\\Users\\user.name\\Documents\\My Tools Data\\Temp\\Demo Phantom Skin\\dicom\\*";
QProcess process;
process.start(program, arguments);
So the message here is that you do not need to try to fix the quotes about whitespaced strings yourself. Qt does it for you automatically. All you need is to correctly split the program and arguments so that Qt knows where to put quotes.

Authenticating with OpenLDAP from PHP

Using CentOS 7.5, Apache 2.4.6. Running in a VM. No SSL.
I followed https://linuxhostsupport.com/blog/how-to-install-ldap-on-centos-7/ and configured OpenLDAP.
From PHP, when I do an anonymous bind, and issue ldap_search, I see the entry for the user.
When binding with the userid & password, the function fails.
P.S: In case I am typing the wrong password, how do I change a password for a user defined in LDAP using ldif file?
Here is the code:
$ds = ldap_connect("localhost"); // must be a valid LDAP server!
echo "LDAP Server connection result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is " . $r . "<br />";
echo "Searching for (sn=*) ...";
// Search surname entry
$sr=ldap_search($ds, "o=Sapphire, ou=karachi", "sn=*");
echo "Search result is " . $sr . "<br />";
echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />";
}
echo "Binding as $userid ... ";
if( $r = ldap_bind($ds, "uid=hussain,ou=People,dc=karachi,dc=sapphire", $password) ){
echo "Userid or Password is valid";
}else{
echo "Userid or Password is not valid";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
Found the answer. I needed to add
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
before issuing the bind.

Qt Creator Sql Update Syntax Error

I am getting sql syntax errors for my update command in qt creator.
QSqlQuery q,q2;
for(int r=0; r<rowtablecount; r++){
q.prepare("update checkdata set "
"alobs=:alobs,"
"payee_name=:payee_name,"
"payee_nature=:payee_nature,"
"account_code=:account_code,"
"amount=:amount,"
"date_paid=:date_paid,"
"cancel_status=:cancel_status,"
"reviewer=:reviewer,"
"preparer=:preparer,"
"reciever=:reciever,"
"reviewer_pos=:reviewer_pos,"
"preparer_pos=:preparer_pos,"
"reciever_pos=:reciever_pos,"
"date_delivered=:date_delivered"
"where check_no = :checkno");
q.bindValue(":checkno", tabledata[r][2]);
qDebug() << tabledata[r][2];
q.bindValue(":alobs",tabledata[r][3]);
q.bindValue(":payee_name",tabledata[r][4]);
q.bindValue(":payee_nature",tabledata[r][5]);
q.bindValue(":account_code",tabledata[r][6]);
q.bindValue(":amount",tabledata[r][7].toDouble());
q.bindValue(":date_paid",tabledata[r][10]);
q.bindValue(":reviewer",reviewer);
q.bindValue(":preparer",preparer);
q.bindValue(":reciever",reciever);
q.bindValue(":reviewer_pos",reviewer_pos);
q.bindValue(":preparer_pos",preparer_pos);
q.bindValue(":reciever_pos",reciever_pos);
q.bindValue(":date_delivered",tabledata[r][9]);
q.bindValue(":acicn", acic_value);
q2.prepare("update acic set date_prepared=:date_prepared, total_amount=:total_amount where acic_num=:acic_num");
q2.bindValue(":date_prepared",tabledata[r][1]);
q2.bindValue(":total_amount",tabledata[r][8]);
q2.bindValue(":acic_num", acic_value);
if(!q.exec()){
if(q.lastError().isValid())
qDebug() << q.lastError().text() << " <error " << r;
QMessageBox::critical(this,tr("Error: Entry Failed"),tr("Data Field incorrect."));
if(!q2.exec()){
if(q2.lastError().isValid())
qDebug() << q2.lastError().text() << " <error " << r;
QMessageBox::critical(this,tr("Error: Entry Failed"),tr("Data Field incorrect."));
From the above, I get this error, repeated 3 times due to for loop:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check_no = '1248973'' at line 1 QMYSQL: Unable to execute query"
I suspect it is either the writing of the command in prepare, or perhaps reserved word, but I cannot find it.
Ideas on this would be most helpful.
It seems that I am a complete idiot for not seeing this. The error is in the line before "where check_no = :check_no". It just needs a space.
Thanks to Abhik Chakraborty for pointing it out.

Perl replaces single quotes to double quotes string

My Script want to replace or remove the single quotes with double quotes
str_replace(rtrim(c_manager),~s/\'/\'\'/g) this line cannot work it out..
Example: k'amal
Result : k"amal or kamal
$sql = 'select rtrim(f_admin_disabled),'."\n".
' convert(varchar,t_password,101),'."\n".
' rtrim(c_email),'."\n".
' str_replace(rtrim(c_manager),~s/\'/\'\'/g),'."\n".
' rtrim(c_mgr_email)'."\n".
' from tuserprofile'."\n".
' where ic_user1 = '."'$user_id'"."\n";
$sth = $dbh->prepare("$sql")
or err("Database error in $sql", "Error preparing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->execute or err("Database error in $sql", "Error executing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->bind_columns(\$prev_status, \$prev_date, \$prev_email, \$prev_mngr_name, \$prev_mngr_email);
$sth->fetch();
$sth->finish();
if($user_email ne $prev_email){
$sql = 'declare #result int'."\n".
'exec #result = ap_recert_update '."'$user_id', '$prev_date', ".
"'$prev_status', '$user_email', ".
"'$prev_mngr_name', '$prev_mngr_email' "."\n".
'SELECT #result'."\n";
$sth = $dbh->prepare("$sql")
or err("Database error in $sql", "Error preparing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->execute or err("Database error in $sql", "Error executing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->bind_columns( \$result);
$sth->fetch();
if($result < 0){
err("", $user_id."\t".$result, 0);
$problem = $problem.$user_id."\t".$result."\n";
}
$sth->finish();
}
}
}
Don't include your variables directly in your sql statements. Instead use placeholders and bind variables.
Cleaning up your first sql statement would be done like follows:
my $sql = q{select rtrim(f_admin_disabled),
convert(varchar,t_password,101),
rtrim(c_email),
str_replace(rtrim(c_manager),~s/'/''/g),
rtrim(c_mgr_email)
from tuserprofile
where ic_user1 =?};
$sth = $dbh->prepare($sql)
or err("Database error in $sql", "Error preparing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->execute($user_id) or err("Database error in $sql", "Error executing SQL statement:\r\n\n" . $dbh->errstr, 3);
$sth->bind_columns(\($prev_status, $prev_date, $prev_email, $prev_mngr_name, $prev_mngr_email));
$sth->fetch();
$sth->finish();
Also could just use a heredoc for the assignment to $sql
my $sql = <<'END_SQL';
select rtrim(f_admin_disabled),
convert(varchar,t_password,101),
rtrim(c_email),
str_replace(rtrim(c_manager),~s/'/''/g),
rtrim(c_mgr_email)
from tuserprofile
where ic_user1 =?
END_SQL

Maximum string length that can be passed in command line argument?

I already saw this question similar ques for SQL
I am passing content of web page as argument to c++ program.
my code is here:
<?php
//sent has value "http://www.paulgraham.com/herd.html"
$url=$_POST['sent'];
$text = file_get_contents($url);
$temp=strip_tags($text);
$output=shell_exec("/home/technoworld/Videos/LinSocket/Modular/x '$temp'");
echo $output;
?>
Which gives output for small content only. Output I get is
most : 1 in : 1 investors : 1 component : 1 2013The : 1 biggest : 1 August : 1 Dynamics : 1 Herd : 1 Investor : 1 Maximum Occurrences Investor Herd Dynamics August 2013The biggest component in most investors
While actually it show gives count for each word.
Manually when I execute my program in command line:
./x "string"
It works and gives correct result for first paragraph of "http://www.paulgraham.com/herd.html"
. But it does not pass second and next para content in argument. It just write it on command line.
How can I pass such a content in argument? For small content it gives correct output.
getconf ARG_MAX
Argument list allowed for my system is : 2097152
I've changed your PHP program to use escapeshellarg as follows. I didn't test it, but my guess is that it will work
<?php
//sent has value "http://www.paulgraham.com/herd.html"
$url=$_POST['sent'];
$text = file_get_contents($url);
$temp=escapeshellarg(strip_tags($text));
$output=shell_exec("/home/technoworld/Videos/LinSocket/Modular/x " . $temp);
echo $output;
?>
You might modify the C++ and PHP sources and build a pipe.
C++
int main () {
std::ostringstream txt;
txt << std::cin.rdbuf();
std::cout << "Input: \n" << txt.str() << std::endl;
return 0;
}
PHP
<?php
$pipe = popen('Debug/Test', 'w');
if( ! $pipe) {
// Error
}
else {
$txt = 'Hello World';
fwrite($pipe, $txt, strlen($txt));
pclose($pipe);
}
?>