如何让2个CMD窗口相互“交谈”?(How to get 2 CMD windows to 'talk' to each other?)
我可能错过了正确的词汇来更简洁地谈论这个问题所以请原谅我,如果我在这里有点罗嗦。 在Windows 10下我有一个在CMD命令提示符下运行的程序它是一个名为OpenSim的可执行文件,它有自己广泛的命令集,包括'shutdown',它启动其中进程的正常终止,关闭SQL连接等,最后关闭CMD命令窗口。 我还有一个CMD .bat文件,当电源关闭时由我的UPS激活,当然会打开它自己的窗口,然后在关闭硬件之前做一些内务处理。 我希望.bat文件做的一件事是以某种方式将'shutdown'命令插入到另一个窗口的进程中。 那可能吗? 如果是这样,怎么样? 请假设我是一个全新的人,你不会走错路。 谢谢。
编辑看起来创建一个文件来标记发生的关闭事件是唯一(并且我猜相当原始)的方式来做到这一点。 因此,基于其他人在stackoverflow中所说的内容,我现在有以下内容。 当我运行它来测试它等待 - 它没有。 它一直运行到最后,运行'shutdown',即使UPSFLAG.TXT文件不存在。 出了什么问题?
echo Waiting for UPS Power Down Signal. echo ================================= @ECHO OFF SET LookForFile="C:\Opensim OSGrid\UPSFLAG.TXT" :CheckForFile IF EXIST %LookForFile% GOTO FoundIt REM If we get here, the file is not found. REM Wait 10 seconds and then recheck. REM If no delay is needed, comment/remove the timeout line. TIMEOUT /T 10 >nul GOTO CheckForFile :FoundIt ECHO Found: %LookForFile% rem Tidy up del "C:\Opensim OSGrid\UPSFLAG.TXT" shutdown
I am probably missing the right vocabulary to talk about this problem more succinctly so excuse me if I'm a little wordy here. Under Windows 10 I have a program that runs inside a CMD command prompt It's an executable called OpenSim and it has it's own extensive command set, including 'shutdown', which initiates a graceful termination of the processes therein, closes SQL connections etc, then finally closes the CMD command window. I also have a CMD .bat file that is activated by my UPS when the power goes down that will of course open it's own window, and then does some housekeeping before closing down the hardware. One thing I want the .bat file to do is to somehow insert a 'shutdown'command into the other window's process. Is that possible? If so, how? Please assume I am a total newbie at this and you won't go far wrong. Thank you.
EDIT It looks like creating a file to flag the closedown event taking place is the only (and I guess rather primitive) way to do this. So, building on what others have said in stackoverflow, I have the following now. When I run it to test it waits - it doesn't. It runs right through to the end, running 'shutdown', even though the UPSFLAG.TXT file does not exist. What's going wrong?
echo Waiting for UPS Power Down Signal. echo ================================= @ECHO OFF SET LookForFile="C:\Opensim OSGrid\UPSFLAG.TXT" :CheckForFile IF EXIST %LookForFile% GOTO FoundIt REM If we get here, the file is not found. REM Wait 10 seconds and then recheck. REM If no delay is needed, comment/remove the timeout line. TIMEOUT /T 10 >nul GOTO CheckForFile :FoundIt ECHO Found: %LookForFile% rem Tidy up del "C:\Opensim OSGrid\UPSFLAG.TXT" shutdown
原文:https://stackoverflow.com/questions/44504808
最满意答案
内容的属性存在。 这只是print_r()的一个技巧,以及它如何与内存中的XML对象一起使用。
$x = simplexml_load_string('<page id="id1"><content name="abc">def</content></page>'); print_r($x->content); print_r($x->content['name']); SimpleXMLElement Object ( [@attributes] => Array ( [name] => abc ) [0] => def ) SimpleXMLElement Object ( [0] => abc )
$x = simplexml_load_string('<page id="id1"><content name="abc">def</content></page>');
To get the node's attributes:
$attributes = $x->content->attributes(); //where content is the name of the node $name = $attributes['name'];
To get the
content
node's content:$c = $x->content;
Interesting, that $c can be used as string and as object, i.e.
echo $c; //prints string print_r($c) //prints it out as object
相关问答
更多-
根据http://php.net/manual/en/simplexmlelement.construct.php我调整了这样的代码: xpath('//metadata/page/filename[.="services.php"]/parent::*'); $res ...
-
这似乎是我使用了错误的帮助函数。 我将我的XML移动到laravel资源文件夹并使用该函数访问路径 $path = resource_path('xml/words.xml'); 谢谢你的帮助! It seems like I used the wrong helper-function. I moved my xml to the laravel resources folder and access the path with the function $path = resource_path(' ...
-
去掉 从文件的末尾。 没有开始标记
,有一个格式声明,不需要关闭。 Remove from the end of file. There is no opening tag, there is a declaration of format which does not require closing. -
使用preg_replace和\s从链接中删除未识别的(和未指定的)空格,它代表任何空格字符: $link = ' http://www.example.com'; $link = preg_replace("/\s+/", "", $link); echo ">" . $link . "<" . PHP_EOL; 输出: >http://www.example.com< 您现在应该可以使用simplexml_load_file($link);加载它simplexml_load ...
-
替换用simplexml_load_file()加载的xml中的文本?(Replace text in xml loaded with simplexml_load_file()?)[2024-03-24]
如果您只想重命名和 标签,我建议您使用最简单的解决方案,即使用str_replace替换文本。 $xml_external_path = 'http://external-site.com/original.xml'; $xml = simplexml_load_file($xml_external_path); $searches = [' ']; $replacement ...', ' ', '', ' -
这部分代码: $element['updated'] = strtotime($item->updated, time()); 对于所有元素似乎总是相同的,并且可能覆盖所有数组。 您的$item似乎在第二个循环中始终相同。 This part of code: $element['updated'] = strtotime($item->updated, time()); Seems to be always the same for all the elements and that may be o ...
-
simplexml_load_file只返回xml的部分数据[重复](simplexml_load_file only return partial data of xml [duplicate])[2021-12-11]
您忘记添加其他参数以获取CDATA字符数据。 尝试这个: $url = "http://www.thestar.com.my/RSS/Lifestyle/Women/"; $xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); echo ""; print_r($xml); You forgot to add an additional parameters to get the CDATA Character ...
-
内容的属性存在。 这只是print_r()的一个技巧,以及它如何与内存中的XML对象一起使用。 $x = simplexml_load_string('
'); print_r($x->content); print_r($x->content['name']); SimpleXMLElement Object ( [@attributes] => Array ( ...def -
PHP:如何使用simplexml_load_file()var(PHP: How to get
working in a simplexml_load_file() var)[2022-09-30]两种方法使它工作。 正确的那一个 不要存放那些。 存储真实的实际换行符,例如Line 1. Line 2. 然后使用nl2br()用HTML标记替换换行符。 这假设您的描述通常不包含标记。 如果是,请使用另一个答案中提出的CDATA部分。 另一个 $descText = strip_tags($xml->aboutModule->chocolaterie->desc->asXML(), '
'); Two ways to make it ... -
不要调用htmlspecialchars ,它将所有XML标记转换为HTML实体。 asXML(); $pattern = "/"; $result = preg_match($pattern,$text); echo $result; ?> Don't call htmlspecial ...