首页 \ 问答 \ 将多个输出同时输出到同一个文件?(pipe many outputs to same file at the same time?)

将多个输出同时输出到同一个文件?(pipe many outputs to same file at the same time?)

假设我有一个bash脚本:

#!/bin/bash
php ./listen.php 3001 3003 26 &
php ./listen.php 3002 3004 120 &

我可以将它们全部同时输出到相同的输出日志文件中吗? 例:

#!/bin/bash
php ./listen.php 3001 3003 26 >/tmp/log 2>&1 &
php ./listen.php 3002 3004 120 >/tmp/log 2>&1 &

Say i have a bash script:

#!/bin/bash
php ./listen.php 3001 3003 26 &
php ./listen.php 3002 3004 120 &

can i pipe all of them to same output log file at the same time without conflict? example:

#!/bin/bash
php ./listen.php 3001 3003 26 >/tmp/log 2>&1 &
php ./listen.php 3002 3004 120 >/tmp/log 2>&1 &

原文:https://stackoverflow.com/questions/2096704
更新时间:2023-09-18 20:09

最满意答案

字典包含在列表中,这对初学者来说非常混乱。 如果在响应中看到[],则必须使用数字索引来引用这些括号内的内容。 然后你可以通过关键字引用里面的dict。 使用请求获取JSON。

import requests

r = requests.get('http://nominatim.openstreetmap.org/search.php?action=query&format=json&city=Budapest&country=Hungary').json()

print(r[0]['lon'])

print(r[0]['lat'])

产量:19.0404707 47.4983815

进程以退出代码0结束


The dictionary is contained within a list, which very confusing to beginners. If you see []'s in the response, you have to use a numerical index to reference the content inside of those brackets. Then you can reference by keyword for the dict inside. Use requests to fetch JSON.

import requests

r = requests.get('http://nominatim.openstreetmap.org/search.php?action=query&format=json&city=Budapest&country=Hungary').json()

print(r[0]['lon'])

print(r[0]['lat'])

Output: 19.0404707 47.4983815

Process finished with exit code 0

相关问答

更多
  • 尝试这个: JSONP.get( 'MyURL.php', {Email:'MyEmail', Password:'MyPass'}, function(data){ for (var i = 0; i < response.length; i++) { str = response[i].NE; str2 = response[i].EMAIL; str3 = response[i].TIPE; str4 = respon ...
  • 字典包含在列表中,这对初学者来说非常混乱。 如果在响应中看到[],则必须使用数字索引来引用这些括号内的内容。 然后你可以通过关键字引用里面的dict。 使用请求获取JSON。 import requests r = requests.get('http://nominatim.openstreetmap.org/search.php?action=query&format=json&city=Budapest&country=Hungary').json() print(r[0]['lon']) pr ...
  • import json with open('data.json') as data_file: data_string = data_file.read() try: data = json.loads(data_string) print('Success!') except ValueError: print('Failed:') print(repr(data_string)) 如果失败,请向我 ...
  • 您无法解析DateTime.Now 。 它已经返回DateTime ,而不是string 。 您可以使用yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'格式生成字符串字符串表示形式,并使用InvariantCulture等适当的文化格式; DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture) You can't parse DateTime.Now. It alread ...
  • 做得太多了,现在已经解决了这个问题。 对象到JSON仍然不是dd-MM-yyyy格式,例如16-08-2015会被解释为一个单独的日期,因为February X in 22会查看那个 @Override public void configureJacksonObjectMapper(ObjectMapper objectMapper) { objectMapper.setDateFormat(new SimpleDateFormat("dd-MM-yyyy")); } 更新: 另一 ...
  • 不需要特殊的库,您拥有获取任何窗口的显示并保存到文件所需的一切。 像这样的Simething: 1 def OnSaveToFile( self, event ): 2 context = wx.ClientDC( self ) 3 memory = wx.MemoryDC( ) 4 x, y = self.ClientSize 5 bitmap = wx.EmptyBitmap( x, y, -1 ) 6 ...
  • 那是因为json变量包含一个json对象而不是一个json字符串。 当您将其更改为字符串时,一切都按预期工作。 var jsonStr = '{"result": "success"}'; var ajaxres = JSON.parse(jsonStr); console.log(ajaxres.result); var json = { "result": "success" } console.log(json.result);
    Thats because ...
  • 您可以使用$.getJSON 例: $.getJSON( "url/to/file.json", function(data) { var items = []; $.each( data, function( key, val ) { items.push( key + ': ' + val ); }); console.log( 'items: ', items ); }); Ok, I have solved the problem. First I iterate thre ...
  • 由于您的字符串必须是ISO日期格式,您可以像下面的代码一样更改它: let timestamp : string = "2017:03:22 08:45:22"; let timestampISO : string = timestamp.replace(':','-').replace(':','-').replace(' ','T'); let time = new Date(timestampISO); console.log("Time: ",time); Since your s ...
  • 它是一个JsonArray而不是一个简单的JsonObject 试试这个: JSONArray a = new JSONArray(json); for (int i = 0; i < a.length(); i++) { JSONObject row = a.getJSONObject(i); Log.d("json", ""+row); } It is a JsonArray not a simple JsonObject try this: ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。