带有命令行参数的 C 控制台应用程序中的井号 (#)
我正在尝试将颜色代码从 php 网站发送到端口。为此,我在服务器上使用控制台应用程序。它看起来像这样:
int _tmain(int argc, _TCHAR* argv[])
{
if (argc >= 3)
{
_tprintf ( _T("Command: %s\n"), argv[3]);
if ( !Messenger::GetInstance()->SetServer( argv[1], _tstoi(argv[2]), false) )
{
_tprintf( _T("ERROR: SetServer( 192.168.10.50, 30000, false) failed") );
}
else
{
_TCHAR *p = wcstok(argv[3], _T(";"));
while (p)
{
Messenger::GetInstance()->SendCommand( p );
//_tprintf ( _T("Token: %s\n"), p);
p = wcstok(NULL, _T(";"));
}
}
}
return 0;
}
exe 的调用方式如下:
$command = "Command=LIGHT-COLOR #00ff00";
$returnMsg = exec("PassAlong.exe \"" . $server . "\" \"" . $port . "\" \"" . $command . "\"");
不幸的是,控制台应用程序仅返回以下内容: 命令:LIGHT-COLOR
看起来字符串在井号#处被切断。
有人知道为什么吗?
感谢您的帮助!非常感谢! 基督教
I am trying to send a color code from a php-website to a port. For that I use a console application on the server. It looks like this:
int _tmain(int argc, _TCHAR* argv[])
{
if (argc >= 3)
{
_tprintf ( _T("Command: %s\n"), argv[3]);
if ( !Messenger::GetInstance()->SetServer( argv[1], _tstoi(argv[2]), false) )
{
_tprintf( _T("ERROR: SetServer( 192.168.10.50, 30000, false) failed") );
}
else
{
_TCHAR *p = wcstok(argv[3], _T(";"));
while (p)
{
Messenger::GetInstance()->SendCommand( p );
//_tprintf ( _T("Token: %s\n"), p);
p = wcstok(NULL, _T(";"));
}
}
}
return 0;
}
The exe is called like this:
$command = "Command=LIGHT-COLOR #00ff00";
$returnMsg = exec("PassAlong.exe \"" . $server . "\" \"" . $port . "\" \"" . $command . "\"");
Unfortunately, the console app only returns this:
Command: LIGHT-COLOR
It seems that the string is cut off at the hash sign #.
Does anyone have an idea why?
Thank you for your help! It is much appreciated!
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试转义 #,如下所示:
第一个 '\' 是转义转义 '#' 的 '\'(如果有意义的话)。我不是 PHP 程序员,所以这没有经过测试。
Try escaping the #, like so:
The first '\' is to escape the '\' that escapes the '#' if that makes sense. I am not a PHP programmer, so this isn't tested.