Sending curl command to command prompt using QProcess
-
@JonB Hi, I tried to do what you have suggested
QStringList arg; arg << "-X" << "https://content.dropboxapi.com/2/files/upload" << "--header" << "Authorization: Bearer access_token" << "--header" << fourr << "--header" <<"Content-Type:application/octet-stream"<<"--data-binary"<<fivee; qDebug() << arg; mproc.start("curl",arg); mproc.waitForFinished(); QByteArray output = mproc.readAll(); qDebug().noquote() << output; //four = "Dropbox-API-Arg: {\"path\": \"/Orders/SatNov142020/United_Plof.CSV\\\"}\"" // five = @C:/Users/U/Dropbox/order/United/2020_Sep_07_06_12_25__CSPROD_N.CSV"
I received nothing, no output,
-
QProcess has waitForStart() with a return value, exitCode() and exitStatus() and some more which you should check.
-
@Christian-Ehrlicher exitcode returns (2)
and exitStatus returns QProcess::NormalExit -
So you should check what this return code tells you -
man curl
.
Can you show us how you initialize 'four' ? The debug output doesn't look correct due to the quoted"
You also forgot the second argument. -
this is how i get (four)
char * x = "Dropbox-API-Arg: {\"path\": \"/Orders/"; ba = s.toLocal8Bit(); //s has todays date char *c_str6 = ba.data(); char *threee = new char[strlen(x) + strlen(c_str6) + 1]; strcpy(threee, x); strcat(threee, c_str6); name = "/United_Plof.CSV\\\"}\""; char * fourr = new char[strlen(threee) + strlen(name) + 1]; strcpy(fourr, threee); strcat(fourr, name);
Do you want me to check (man curl) in qprocess.start?
the only thing I wanted is to execute a command on a terminal or command prompt. the command is generated in qt code. -
@Ahsan-Niaz said in Sending curl command to command prompt using QProcess:
//four = "Dropbox-API-Arg: {\"path\": \"/Orders/SatNov142020/United_Plof.CSV\\\"}\""
This at least looks wrong. You should be trying to get the fundamentals right: walk before you can run.
-
Do it with literal-strings first. I did that from the strings you showed me earlier. Putting in variables right now is error-prone. When you have the simplest example working correctly is the time to introduce those.
-
If you want to know how your
QProcess
code is sending the final arguments, write a one-line C/C++ program to just print out receivedargv
contents, and use that as yourcurl
command.
-
-
@JonB
I did it in literal strings as well with the following piece of codeQStringList arg; arg << "-X" << "https://content.dropboxapi.com/2/files/upload" << "--header" << "Authorization: Bearer access_token" << "--header" << "Dropbox-API-Arg: {\"path\": \"/Orders/FriNov132020/United_Plof.CSV\"}" << "--header" <<"Content-Type:application/octet-stream"<<"--data-binary"<<"@C:/Users/U/Dropbox/order/United/2020_Sep_06_06_29_29__CSPROD_N.CSV"; qDebug() << arg; mproc.start("curl",arg); mproc.waitForStarted(); mproc.waitForFinished(); qDebug() << mproc.exitStatus(); QByteArray output = mproc.readAll(); qDebug().noquote() << output;
Still nothing in the output.
-
@Ahsan-Niaz
I think you forgot your "POST".And about the obsolete
start(command)
function, it now usesQProcess::splitCommand
to get arguments from the command.
I use that to print your command and it seems to get a little messy by getting:Dropbox-API-Arg: {\path\: \/Orders/SatNov142020/United_Plof.CSV\}
So I look into the source code of splitCommand and I find this comment:
// handle quoting. tokens can be surrounded by double quotes // "hello world". three consecutive double quotes represent // the quote character itself.
So instead of
\"
, you need"""
to represent the quote character inside double quotes.
So I think\\\"
should be changed to\"\"\"
if you use the obsolete function.
Note1: I'm not encouraging using the obsolete function.
Note2: Hide your access token... -
@Bonnie said in Sending curl command to command prompt using QProcess:
@Ahsan-Niaz
I think you forgot your "POST".You also forgot the second argument.
He does not read the comments so what do you expect?
-
I am really thankful to everyone who replied to me and corrected my mistakes. Your help will help me finish my work quicker.
Thanks @Christian-Ehrlicher , @Bonnie @JonB