首页 \ 问答 \ 将环境传递给父级的python shell脚本执行(python shell script execution that passes environment to the parent)

将环境传递给父级的python shell脚本执行(python shell script execution that passes environment to the parent)

所以我知道subprocess如何工作并使用它很多,但我遇到了一个奇怪的问题。 我需要执行一些环境变量的导出。 原因是某些程序(黑盒)执行的程序似乎在子shell中运行,因此它无法访问环境变量,但它可以访问我的所有文件。

我不能硬编码环境变量,所以我想要source. 包含export命令的文件。 但是,如果我source. 在子进程中的该文件,它不会对其父进程产生任何影响。 在这种情况下,除了subprocess之外,我还需要一些能够执行shell命令而不创建子进程的函数(如果存在)。 另一个问题是子进程没有读取文件的适当权限。

并且通过os复制环境变量也是不可能的。

除了subprocess之外还有什么吗? 或者还有其他一些解决方法吗?


So I know how subprocess works and use it a lot, but I've run into a strange issue. I need to execute an export of some environment variables. The reason is that some program (black-box) executes a program that seems like it runs in a subshell, so it doesn't have access to the environment variables but it has access to all my files.

I can't hard code the environment variables so I want to source or . the file that has the export commands in it. However, if I source or . that file in a subprocess, it won't make any difference to its parent process. In which case I either need some function besides subprocess that can execute shell commands without creating a subprocess, if that exists. Another issue is that a subprocess doesn't have the proper permissions to read the file.

And copying the environment variables via os isn't really possible either.

Does anything besides subprocess exist? Or is there some other kind of workaround?


原文:https://stackoverflow.com/questions/42017394
更新时间:2022-03-01 21:03

最满意答案

您需要为bin/kafka-console-consumer.sh指定不同的值反序列化器。 添加以下内容:

--property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer

默认字符串反序列化器无法正确读取长值。


You need to specify a different value deserializer for bin/kafka-console-consumer.sh. Add the following:

--property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer

Default String deserializer fails to read the long value correctly.

相关问答

更多
  • 1)从远程IBM MQ读取消息(遗留系统仅适用于IBM MQ) 2)将这些消息写入卡夫卡主题 我将使用Kafka的Connect API(1)和(2)。 3)从相同的Kafka主题中读取这些消息并调用REST API。 您可以使用Streams API以及Kafka的较低级别的Consumer API,具体取决于您的喜好。 4)未来可能会有其他消费者阅读此主题。 这可以直接使用 - 根据步骤2将数据存储在Kafka主题中后,许多不同的应用程序和“消费者”都可以独立读取这些数据。 1) Reads messa ...
  • 最好的办法是永远不要将结果返回给驱动程序(通过使用countByKey)。 而是使用reduceByKey以(key, count)的形式返回另一个RDD。 将RDD映射到表的行格式,然后在其上调用saveToCassandra 。 这种方法最重要的优点是我们从不将数据序列化回驱动程序应用程序。 所有信息都保存在集群中,并直接保存到C *,而不是运行驱动程序应用程序的瓶颈。 示例(非常类似于地图减少字数): 将每个元素映射到(键,1) 调用reduceByKey进行更改(键,1) - >(键,计数) 将每个 ...
  • 既然你已经编写了你的Route ,只需要一个来自Entity User ,我认为你不需要Producer.plainSink 。 相反,我认为Producer.send也会起作用。 另外,作为附注,抛出异常不是“惯用的”scala。 所以我改变了无效用户的逻辑: val producer : KafkaProducer = new KafkaProducer(producerSettings) val routes : Route = post { entity(as[User]) { us ...
  • 卡夫卡的加盟总是以钥匙为基础。 因此,要进行任何联接工作,需要在执行实际联接之前将要加入的字段提取到键中(唯一的部分例外是KStream-GlobalKTable联接)。 在您的代码示例中,您将不会得到任何结果,因为所有记录都有一个null键,因此无法加入。 对于连接本身来说,KStream-KTable连接似乎是您的使用案例的正确选择。 要做到这一点,您需要: 为topic1正确设置连接键并将数据写入其他主题(我们称它为topic1Keyed ) 阅读topic1Keyed作为表 为topic2正确设置连 ...
  • 您对连接如何工作的理解是正确的(假设记录时间戳不同比连接窗口大小小)。 对于操纵JsonNode,只需搜索互联网: 如何修改Java中的JsonNode? Your understanding on how the joins work is correct (assuming that the record timestamp different is smaller than the join-window size). For manipulating JsonNodes, just search t ...
  • 你的语法错了:)。 ->只是创建对的操作符,所以表达式 (key,value)-> { println(key) } 有类型((任何,任何),单位),因为编译器不能推断任何类型的信息(和key和value都丢失) 如果你正在使用scala 2.12替换-> with =>应该可以解决问题,但是如果你使用的是旧版本的scala,你将不得不明确地实现java bifunction: textLines.foreach(new BiFunction[T1, T2] { ... }) Your synta ...
  • 是的,使用Kafka Connect -streaming从主题到数据存储正是它的用途:) 如果要在将数据登陆到数据库之前处理/丰富数据,可以使用KStreams(或KSQL),然后流式传输到第二个主题,然后连接到Connect。 Yes, use Kafka Connect—streaming from a topic to a datastore is precisely what it is for :) If you want to process/enrich your data before l ...
  • 如果我有2个输入主题,一个有10个分区,另一个有5个分区 听起来不错。 所以你有15个分区。 假设您有一个简单的处理器拓扑,没有连接和聚合,因此所有15个分区都只是无状态转换。 然后,15个输入分区中的每一个将映射到单个Kafka Streams“任务”。 如果你有1个线程,那么这15个任务的输入将由该1个线程处理。 如果您有15个线程,则每个任务都有一个专用线程来处理其输入。 所以你可以用15个线程运行1个应用程序或者用1个线程运行15个应用程序,它在逻辑上相似:你在15个线程中处理15个任务。 唯一的区 ...
  • 如果你有原始的KTable包含id -> Json数据(让我们称之为dataKTable )你应该能够得到你想要的东西 KTable countKTablePerRange = dataKTable.groupBy(/* map your age-range to be the key*/) .count("someStoreName"); 这适用于所有版本的Kafka Streams API。 更新 关于重新分区主题中的4个值:这是正确的。 对“base KTab ...
  • 您需要为bin/kafka-console-consumer.sh指定不同的值反序列化器。 添加以下内容: --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer 默认字符串反序列化器无法正确读取长值。 You need to specify a different value deserializer for bin/kafka-console-consumer.sh. Add the fo ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)