I have a Squirrel plugin as below:
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.ChangedTag:
print( fe.game_info( Info.Name ) + "\n" );
system( "echo '" + fe.game_info( Info.Name ) + "' > /home/pi/.attract/romlists/ROMNAME.tmp" );
system( "printf '" + fe.game_info( Info.Emulator ) + "' > /home/pi/.attract/romlists/ROMNAME2.tmp" );
break;
}
return false;
}
fe.add_transition_callback( "removefavourite" )
I would like to redirect the output of the "print" command from terminal/console to a file. However, I cannot seem to do so and would be grateful if someone could assist me please.
I've tried alternatives in bash - many variations of the "echo" command and the "printf" command, but these are not effective to capture words which include parentheses eg () or single quotes eg '. The "print" command seems to be effective in all cases but I have not been able to redirect the output.
Please note that I am unable to modify the words I'm capturing first by escaping/backslashing special characters before sending them to print, echo or printf.
Thank you.
答案 0 :(得分:0)
我设法解决了这个问题。我发现“保持它简单,愚蠢”,只是让插件处理一个参数是可行的方法。
我对插件进行了如下更改:
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.ChangedTag:
fe.plugin_command( "/usr/bin/printf1.sh", "\"" + fe.game_info(Info.Name) + "\"" );
system( "sudo /bin/bash /opt/retropie/configs/all/removefavourite.sh" ); // Starts the process of removing the game from Favourites.txt
}
return false;
}
fe.add_transition_callback( "removefavourite" )
此插件将游戏名称发送到我创建的名为“ printf1.sh”的新bash脚本。 bash脚本与“ / usr / bin /”文件夹中的“ printf”命令位于同一文件夹中。 bash脚本必须进入该文件夹,否则会出现“ chdir”(更改目录)错误。
bash脚本的内容是: #!/ bin / bash FILE1 = $ 1 sudo / usr / bin / printf“ $ FILE1”>“ /home/pi/.attract/romlists/REMOVEFAVOURITE.temp”
游戏名称基本上是“参数”,它是从松鼠插件发送到bash脚本的,然后bash脚本将游戏名称(输出)重定向到文件“ REMOVEFAVOURITE.temp”。
此方法的好处是,无论游戏名称采用哪种形式,例如使用单撇号或()或[](例如“ Sam's Journey(c64)”或“ Sam's Journey [c64]”),脚本都将捕获并继续传递下去。特殊字符没有区别。
从那里,我可以使用“ REMOVEFAVOURITE.temp”中记录的信息做任何我想做的事情。